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

user1219721
  • 487
  • 1
  • 6
  • 15

1 Answers1

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.

mgorven
  • 30,615
  • 7
  • 79
  • 122
Radius
  • 559
  • 2
  • 9