Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I got three gateways: on eth0  (default), on eth0:0 on eth0:1

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

how should I proceed ?


share|improve this question
Do you have three gateways, or three IP addresses? – womble Jul 14 '12 at 11:28
both. gateways are 192.168.X.1, and IPs are 192.168.X.200 – user1219721 Jul 15 '12 at 1:21

1 Answer 1

up vote 1 down vote accepted

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 table 1
ip route add default via table 2
ip route add default via table 3

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.