iptables SNAT to another eth ?

Using SUSE ...

From the router .. I can do ping -I eth3 google.com .. and it works .. and I did this in iptables

iptables -t nat -A POSTROUTING -s -o eth3 -j SNAT --to-source

so .. the ip should get routed through eth3 ! . but it doesn't !

x.x.x.x/30 dev eth1  proto kernel  scope link  src x.x.x.x dev eth3  proto kernel  scope link  src dev eth0  proto kernel  scope link  src dev eth0  proto kernel  scope link  src via dev eth0 via dev eth0 dev eth0  scope link dev lo  scope link
default via x.x.x.x dev eth1

:~> ip ro li table T3 dev eth3  scope link  src
default via dev eth3

:~> ip ru li
dexter@GODZILLA:~> ip ru li
0:      from all lookup local
32765:  from lookup T3
32766:  from all lookup main
32767:  from all lookup default

everything else works just fine .. but I want some ips to get through eth3 instead of eth1 !
Who is Participating?
NopiusConnect With a Mentor Commented:
Let's decide what we need. Possible cases:
1) If you need just route all traffic from single host to all destinations via eth3
2) If you need to route all traffic from entire network to all destiations via eth3
3) If you need to route traffic from either 1 host or entire network as in 1) 2) AND muasquerade it as going from address.
4) You need to route or route+masquerade as in 1) 2) 3) but not to all destinations

If I'm guessing right,  you need a case 3) with a single IP.

Then you need to modify both iptables and routing tables.
1) Delete your old rule
iptables -t nat -D POSTROUTING -s -o eth3 -j SNAT --to-source
2) Create a new one:
iptables -t nat -A POSTROUTING -s -o eth3 -j MASQUERADE
3) Now delete old routing rule.
ip rule del prio 32765
4) Add a new rule:
ip rule add from table T3

> so .. the ip should get routed through eth3 ! . but it doesn't !
You almost answered your question -A POSTROUTING means that this rule applies _after_ routing decision.  So that  '-o eth3' never matches your packet (remember that it matches a packet and doesn't route to eth3).
patriciaeldridgeAuthor Commented:
well .. how should it look then ? :D .. I still didn't get it right ! :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.