Policy routing on local packets
I have a linux box with multiple ip addresses:
eth0 -> IP1
eth0:0 -> IP2
eth0:1 -> IP3
eth0:2 -> IP4
All outgoing traffic is using IP1 as source address. But now I want to
use a different IP address (IP1, IP2, IP3 or IP4) as the source address
for all smtp outgoing packets locally generated in my linux box.
I decided to mark such packets like this:
iptables -t mangle -A PREROUTING -p tcp --dport 25 -j MARK --set-mark 0x19
Then I created a new table in /etc/iproute2/rt_tables adding this:
Now the rules and routes:
ip rule add priority 32765 fwmark 0x19 table mytable
ip route add to default dev eth0 via IP_GATEWAY src IP2 table mytable
ip route flush cached
When I do telnet to some smtp host I can see my linux box is still using
IP1 instead of IP2. Then I check iptables statistics "iptables -t mangle
-L -nv" and the number of packets matched (marked) is increasing so...
I think something is not working in my iproute rules.
Does anybody know what am I doing wrong? Thanks