Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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
add comment

1 Answer

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 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.

share|improve this answer
add comment

Your Answer

 
discard

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.