NAT to a broadcast addess using iptables?

This is a discussion on NAT to a broadcast addess using iptables? within the Linux Networking forums, part of the Linux Forums category; Hi, I'm an iptables newbie. I have a busybox router that uses iptables 1.2.8. (Sorry if I ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-27-2006
news@mail.adsl4less.com
 
Posts: n/a
Default NAT to a broadcast addess using iptables?

Hi,

I'm an iptables newbie. I have a busybox router that uses iptables
1.2.8. (Sorry if I have the wrong ng, but this seems to be where the
iptables gurus are!) I have a requirement to be able to send a packet
across the internet and have it natted and forwarded to a directed
broadcast address on the internal lan, e.g. UDP 213.1.2.3:9 -->
10.1.2.255/24:9. I've added the PREROUTING and FORWARDING rules which
nat and foward to the broadcast address but a sniffer shows the packet
not arriving. If I change both rules to a specific host (e.g.
10.1.2.1), it works fine. Is what I'm trying to do possible? (Yes, I
know it's insane, but is it possible!?)

TIA

Reply With Quote
  #2 (permalink)  
Old 11-27-2006
Pascal Hambourg
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?

Hello,

news@mail.adsl4less.com a écrit :
>
> I'm an iptables newbie. I have a busybox router that uses iptables
> 1.2.8. (Sorry if I have the wrong ng, but this seems to be where the
> iptables gurus are!)


Oh, so you're looking for iptables gurus... then don't bother to read my
reply.

> I have a requirement to be able to send a packet
> across the internet and have it natted and forwarded to a directed
> broadcast address on the internal lan, e.g. UDP 213.1.2.3:9 -->
> 10.1.2.255/24:9. I've added the PREROUTING and FORWARDING rules which
> nat and foward to the broadcast address but a sniffer shows the packet
> not arriving. If I change both rules to a specific host (e.g.
> 10.1.2.1), it works fine. Is what I'm trying to do possible?


Netfilter/iptables itself does not care whether an IP addresse is a
broadcast or unicast address (which can cause trouble with connection
tracking). But in the Linux kernel IP stack, the DNAT operation in the
PREROUTING chain takes place before the input routing decision is taken.
So the input routing algorithm receives a packet with a broadcast
destination address, but it won't forward such packets. Broadcast
packets can only be sent or received locally, not forwarded.

> (Yes, I know it's insane, but is it possible!?)


I'm afraid it is not possible to do this with iptables. Is your goal to
do some kind of remote wake-on-LAN ?
Reply With Quote
  #3 (permalink)  
Old 11-27-2006
news@mail.adsl4less.com
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?


Pascal Hambourg wrote:
> Hello,
>
> news@mail.adsl4less.com a écrit :
>
> Oh, so you're looking for iptables gurus... then don't bother to read my
> reply.


LOL

>
> Netfilter/iptables itself does not care whether an IP addresse is a
> broadcast or unicast address (which can cause trouble with connection
> tracking). But in the Linux kernel IP stack, the DNAT operation in the
> PREROUTING chain takes place before the input routing decision is taken.
> So the input routing algorithm receives a packet with a broadcast
> destination address, but it won't forward such packets. Broadcast
> packets can only be sent or received locally, not forwarded.
>
> > (Yes, I know it's insane, but is it possible!?)

>
> I'm afraid it is not possible to do this with iptables. Is your goal to
> do some kind of remote wake-on-LAN ?


Indeed it is - exactly that.

Reply With Quote
  #4 (permalink)  
Old 11-27-2006
Pascal Hambourg
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?

news@mail.adsl4less.com a écrit :
>>
>>I'm afraid it is not possible to do this with iptables. Is your goal to
>>do some kind of remote wake-on-LAN ?

>
> Indeed it is - exactly that.


The problem with sending unicast packets to a sleeping host is ARP
resolution. If your router supports the 'arp' or 'ip' commands, you
could try to add a static ARP entry for your target IP address on the
router :

$ arp -s <target_ip_addr> <target_mac_addr>

or

$ ip neigh add <target_ip_addr> lladdr <target_mac_addr> dev <lan_iface>
Reply With Quote
  #5 (permalink)  
Old 11-27-2006
news@mail.adsl4less.com
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?


Pascal Hambourg wrote:
>
> The problem with sending unicast packets to a sleeping host is ARP
> resolution. If your router supports the 'arp' or 'ip' commands, you
> could try to add a static ARP entry for your target IP address on the
> router :
>
> $ arp -s <target_ip_addr> <target_mac_addr>
>
> or
>
> $ ip neigh add <target_ip_addr> lladdr <target_mac_addr> dev <lan_iface>


But, the magic packet can be sent to either the mac address of the
target or the broadcast ethernet address. As I planned for the latter,
I didn't think that ARP resolution is a problem. Hovever, if I
understand you correctly, there's no way to configure the router to
allow the directed subnet broadcast, so you're saying that I'd have to
direct a packet to a specific IP address and use a static arp entry to
force the packet to go to a specific mac address?

Reply With Quote
  #6 (permalink)  
Old 11-28-2006
Pascal Hambourg
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?

news@mail.adsl4less.com a écrit :
>
> But, the magic packet can be sent to either the mac address of the
> target or the broadcast ethernet address. As I planned for the latter,
> I didn't think that ARP resolution is a problem.


Correct. This is the advantage of the IP directed broadcast address
which is translated into the ethernet broadcast address without ARP
resolution.

> Hovever, if I
> understand you correctly, there's no way to configure the router to
> allow the directed subnet broadcast,


Indeed, I'm afraid no.

> so you're saying that I'd have to
> direct a packet to a specific IP address and use a static arp entry to
> force the packet to go to a specific mac address?


Yes. You could also set the static ARP entry so that the chosen unicast
IP address resolves into the broadcast ethernet address.
Reply With Quote
  #7 (permalink)  
Old 11-29-2006
news@mail.adsl4less.com
 
Posts: n/a
Default Re: NAT to a broadcast addess using iptables?

Pascal Hambourg wrote:
>
> Yes. You could also set the static ARP entry so that the chosen unicast
> IP address resolves into the broadcast ethernet address.

A very cunning plan indeed! I'll give it a go. Many thanks.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:11 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0