I'm trying to setup some kind of "uninterruptible Internet supply" for a Linux machine. For this reason I'm using two uplinks: a standard wired connection via eth0, and additionally a 3G connection which is available via eth1. The wired eth0 connection should be the default connection, while the eth1 connection should only be used in case of a connection problem via eth0. Both interfaces are configured via DHCP.

Current setup

I'm having two default routes via eth0 and eth1 respectively, and I've assigned a higher metric value to eth1 so that eth0 is preferred by default. Basically, this is working fine: when unplugging the ethernet cable from the eth0 port, the system seamlessly continues to use eth1 for any Internet access, since it detects that the eth0 cable became unplugged, and thus can immediately remove the dead eth0 entries from the routing table (which seems to be the default behavior).

The problem

I'm however facing a problem when the wired connection is not directly interrupted at the eth0 interface itself, but at some later point in the network instead. In this case, the Linux machine of course can't detect that some cable has been unplugged, keeps the eth0 entries within the routing table, and any Internet connection attempt fails with a "target network unreachable" error.

So, is there some way to tell Linux to immediately discard the eth0 route if it can't be used to reach the target network? And if yes, how would I detect when the eth0 connection becomes available again, so that I can switch back from eth1 to eth0 again? Is this possible at all?

Thank you very much for any hints!!

  • 1
    You need to use a script or program to test the connection periodically and make a nuanced decision of whether you want to consider it available or not. – David Schwartz Sep 22 '14 at 15:09

Routing protocols are meant to solve this problem in an internal network. OSPF, etc. find adjacent neighbors and implement a "keep-alive" system - whereby if they don't receive confirmation of keep alives, they assume the route is dead and rewrite routing tables in realtime.

If you control anything beyond eth0, consider setting something up like that. I think quagga is the package/software you may want to look into. There's probably simpler solutions that don't involve routing protocols.

If eth0 directly goes to the Internet, which is a network you don't control, you'll need to have some sort of scheduled task check for real connectivity (pinging an outside server, etc.) and manually kill your interface or rewrite your routes when unreachability is discovered.

  • Thank you very much for your answer. Unfortunately, I don't control any devices between eth0 and the Internet uplink. Is there some standard software I can use to rewrite rules on unreachability, or do I need to hack this on my own? If yes, can you point me in the right direction on how to do this? – emkey08 Sep 22 '14 at 15:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.