0

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!

mechyeti
  • 1
  • 1
  • Just add your interface names / corresponding ip addresses to the script. – Tim_Stewart Oct 18 '20 at 18:07
  • 1
    @Tim_Stewart I definitely consider this as a possible solution but was hoping for something that used configuration rather than scripting. Is there any other way to do this with things like route metrics? Regarless, I will take a look at the scripting and give it a try! – mechyeti Oct 19 '20 at 20:19
  • You are getting into an area that I would recommend an advanced router for. PfSense or similar in-between the two ISP devices, as mentioned in the bottom of that answer. Routes will be static. The script is dynamic, and the router option would also be dynamic. The dynamic solutions allow for growth/change later, the router being the best of all options because you can fully utilize both connections. – Tim_Stewart Oct 19 '20 at 20:43
  • Thank you @Tim_Stewart! – mechyeti Oct 20 '20 at 14:56

0 Answers0