1

I got three gateways:

192.168.10.1 on eth0  (default),
192.168.100.1 on eth0:0
192.168.101.1 on eth0:1

I'm trying to make my computer decide on which to use, from the request port. (request comes server-side)

exemple.com:80 -> via 192.168.10.1  to exemple.com:80
exemple.com:81 -> via 192.168.100.1 to exemple.com:80
exemple.com:82 -> via 192.168.101.1 to exemple.com:80

how should I proceed ?

thanks

2
  • Do you have three gateways, or three IP addresses?
    – womble
    Jul 14, 2012 at 11:28
  • both. gateways are 192.168.X.1, and IPs are 192.168.X.200 Jul 15, 2012 at 1:21

1 Answer 1

2

You should mark the traffic with iptables first, then you can set rules to handle the traffic accordingly, something along this lines:

iptables -A PREROUTING -p tcp --dport 80 -t mangle -j MARK --set-mark 1
iptables -A PREROUTING -p tcp --dport 81 -t mangle -j MARK --set-mark 2
iptables -A PREROUTING -p tcp --dport 82 -t mangle -j MARK --set-mark 3

ip rule add fwmark 1 table 1
ip rule add fwmark 2 table 2
ip rule add fwmark 3 table 3

ip route add default via 192.168.10.1 table 1
ip route add default via 192.168.100.1 table 2
ip route add default via 192.168.101.1 table 3

Of course next hop needs to handle NAT/etc and I didn't check syntax.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .