Multiple default gateways in Linux
We have a web server which can be accessed via two different internet connections. So far the secondary connection has been using NAT on the firewall in order since the default gateway in the web server points to the primary connection. However, when using NAT you miss all web statistics.
So, I decided to find out whether it is possible to use multiple default gateways in Linux. The approach would be to use 2 different virtual IP addresses on the box and have different default gateways depending on which virtual IP is accessed.
This turned out to be very easy indeed using iptables.
The box is running RedHat 9 using iptables 1.2.7a.
All needed was this:
/sbin/ip rule add from 10.2.4.12 table T1
/sbin/ip route flush cache