I'm would like to make linux send any socket connections that originate
on the local system to travel out a gateway different that the default
gateway.
This is my current network:
[---------------- THE INTERNET -------------------]
| | | |
[gw0: 192.168.2.1] [gw1: 192.168.2.2]
| | | |
[----------------- 192.168.2.0/24 -------------------]
| |
[host0: 192.168.2.100]
Here is the current routing table on host0:
> ip route show table main
192.168.2.0/24 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 192.168.2.1 dev eth0
After briefly consulting this document:
http://linux-ip.net/html/adv-multi-internet.html
I think I've found a solution.
I first added a second routing table:
> ip route show table 4
192.168.2.0/24 dev eth0 scope link
127.0.0.0/8 dev lo scope link
default via 192.168.2.2 dev eth0
Then I made some iptable rules:
> iptables -t mangle -A PREROUTING -p tcp -s 192.168.2.0/24 -j MARK --set-mark 4
> iptables -t mangle -nvL
Chain PREROUTING (policy ACCEPT 91807 packets, 52M bytes)
pkts bytes target prot opt in out source
destination
16169 2872K MARK tcp -- * * 192.168.2.0/24
0.0.0.0/0 MARK set 0x4
Chain OUTPUT (policy ACCEPT 83576 packets, 29M bytes)
pkts bytes target prot opt in out source
destination
And then finally added one last ip rule:
> ip rule add fwmark 4 table 4
> ip rule show
0: from all lookup local
32765: from all fwmark 4 lookup 4
32766: from all lookup main
32767: from all lookup 253
I tried this out, and it didn't work. I do not see traffic originating
on the system appear route to gw1, traffic that originates from gw0
routes fine. And traffic originating on the system still routes to gw0.
Any help would be appreciated.
Thanks,
Chris