Skip to contentSkip to conversation

SNAT from multiple interfaces with the same IP?

DISCUSSION Carl-Daniel Hailfinger 3 participants 6 messages Dec 4, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

some time ago, I read that netfilter is unable to perform SNAT for identical ranges on different interfaces.

Scenario:

eth0: 192.168.0.1/16
eth1: 192.168.0.1/16
eth2: 10.2.0.1/8

iptables -t nat -A POSTROUTING -i eth0 -s 192.168.0.0/16 -j SNAT --to-source 10.0.0.0-10.0.255.255 iptables -t nat -A POSTROUTING -i eth1 -s 192.168.0.0/16 -j SNAT --to-source 10.1.0.0-10.1.255.255

Will that work or is connection tracking unable to differentiate between the 192.168/16 subnets on eth0 and eth1? My problem is that although the ranges on eth0 and eth1 are sparsely populated, some IPs exist in both networks. Communication between the networks on eth0 and eth1 is not necessary, I just want them to be able to communicate with the outside (on eth2).

If this is not possible, is there a patch in POM or something else with which I can achieve my goal with only one machine.

Regards,
Carl-Daniel

#1 lore raw
Quoted 16 lines · Carl-Daniel Hailfinger

Hi,

some time ago, I read that netfilter is unable to perform SNAT for identical ranges on different interfaces.

Scenario:

eth0: 192.168.0.1/16
eth1: 192.168.0.1/16
eth2: 10.2.0.1/8

iptables -t nat -A POSTROUTING -i eth0 -s 192.168.0.0/16 -j SNAT --to-source 10.0.0.0-10.0.255.255
iptables -t nat -A POSTROUTING -i eth1 -s 192.168.0.0/16 -j SNAT --to-source 10.1.0.0-10.1.255.255

Quoted 6 lines

Will that work or is connection tracking unable to differentiate between the 192.168/16 subnets on eth0 and eth1? My problem is that although the ranges on eth0 and eth1 are sparsely populated, some IPs exist in both networks. Communication between the networks on eth0 and eth1 is not necessary, I just want them to be able to communicate with the outside (on eth2).

I don't see why it wouldn't work, but you can't use -i in POSTROUTING directly, you need to mark the packets or just SNAT unconditionally.

#2 lore raw
Quoted 2 lines · Patrick McHardy

I don't see why it wouldn't work, but you can't use -i in POSTROUTING directly,

BTW, I've always wondered why exactly...

Quoted 1 line

you need to mark the packets or just SNAT unconditionally.

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/
#3 lore raw
Quoted 8 lines · Herve Eychenne
Quoted 2 lines · Patrick McHardy

I don't see why it wouldn't work, but you can't use -i in POSTROUTING directly,

BTW, I've always wondered why exactly...

Two reasons:

- The incoming interface is not known anymore in POST_ROUTING
- Locally generated packets don't even have an incoming interface

#4 lore raw
Quoted 8 lines · Patrick McHardy
Quoted 7 lines · Herve Eychenne
Quoted 2 lines · Patrick McHardy

I don't see why it wouldn't work, but you can't use -i in POSTROUTING directly,

Quoted 5 lines
Quoted 1 line

BTW, I've always wondered why exactly...

Two reasons:

- The incoming interface is not known anymore in POST_ROUTING

Sorry, but... why? (that was my question indeed)

Quoted 1 line

- Locally generated packets don't even have an incoming interface

So what?
If you could use -i, then locally generated packets wouldn't match (that's not a problem because you would do it on purpose). If you don't, it would work as it used to till now.

Herve

Signature · 4 lines
 _
(°=  Hervé Eychenne
//)
v_/_ WallFire project:  http://www.wallfire.org/
#5 lore raw
Quoted 5 lines · Herve Eychenne
Quoted 1 line · Patrick McHardy

- The incoming interface is not known anymore in POST_ROUTING

Sorry, but... why? (that was my question indeed)

In the input path the incoming interface is stored in the skb in skb->dev. On the output path (POST_ROUTING) it contains the outgoing interface. This might actually be changeable with not too much effort, one of my IPsec patches already reorders the POST_ROUTING hook.

Quoted 6 lines
Quoted 1 line

- Locally generated packets don't even have an incoming interface

So what?
If you could use -i, then locally generated packets wouldn't match (that's not a problem because you would do it on purpose). If you don't, it would work as it used to till now.

Yes, that wouldn't be problem.