I am trying to set up a fallback connection on a Linux machine that has access to two different routers on different subnets on running on the same network. I have been reading several other posts related to this but am struggling to get it to work. The setup is as follows:
Internet 1 Internet 2
^ ^
| |
-------------------- ------------------------
[Router 1: 10.1.1.1] [Router 2: 192.168.2.10]
-------------------- ------------------------
^ ^
| |
\ /
--------------------------
[eth0 eth0:1]
[10.1.1.14 192.168.2.50]
[ linux machine ]
--------------------------
In this example, eth0 is configured with DHCP, and eth0:1 is configured as a static IP. I want to connect via the internet on the router at 192.168.2.10, but fall back to the router at 10.1.1.1 if 192.168.2.10 is unreachable. According to some other posts I was reading, it seemed setting route metrics on the default routes should do the trick. I ran the following on the linux machine and tested by unplugging the router at 192.168.2.10 to ensure that it would fallback to 10.1.1.1:
ip route add default via 192.168.2.50 dev eth0 metric 100
ip route add default via 10.1.1.1 dev eth0 metric 200
Running a route -n showed:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.10 0.0.0.0 UG 100 0 0 eth0
0.0.0.0 10.1.1.1 0.0.0.0 UG 200 0 0 eth0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
But a simple ping to Google DNS failed. Removing the 192.168.2.10 route allows it to work just fine. What am I missing, or am I interpreting the route metric wrong? Is there a better way to do this?
I have seen other cases where the routes are added to different tables, and then ip rules are setup for certain IPs to use different connections, but I want all connections to try to go out Router 2 but to go out Router 1 if Router 2 is down.
Thanks!