[SOLVED] Easy way to automatically switch between two network adapters depending on which of the two has internet access
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Easy way to automatically switch between two network adapters depending on which of the two has internet access
I have two network adapters connecting to different isp's. One isp provides a faster service but it fails too often.
Is there a simple way to automatically switch between the two network adapters depending on which one has connectivity to the internet at a given time?
Such as a change in a configuration file somewhere? Ideally, something simple. Or software simple to configure.
You could simply move the default route from one interface to the other, either by hand or by some means of detecting connectivity loss in a script (maybe by pinging 8.8.8.8?).
How do you change the default route from eth0 to eth1 when eth0 has a dhcp-leased IP of the form 192.168.0.* and 192.168.0.1 as the default gateway while eth1 has an IP like 192.168.1.* and 192.168.1.1 as the gateway.
When firefox fails to connect to a site, does this fact appear somewhere that a script can read and respond by changing the default route?
Can't recommend doing that, as Firefox would not know if the site is offline, or if your ISP connection has gone bad.
Better to monitor the availability of something more robust (like 8.8.8.8) in a script to control your default route.
The easy way is to get a router/modem that supports failover HA. You may have it already. Pretty sure the open software like dd-wrt on good router support it.
I used to recommend one running a common bsd virtual machine to act as a failover. You could add in firewall there too.
You can also look at the many web pages on linux for failover and HA. Almost all of them are not easy click and forget. Many of the examples get rather complex.
What was being proposed here and bonding are very different things.
Bonding works by monitoring the link status or via LACP to detect a failure. It's very much a layer-2 solution.
The original question concerns triggering a path change on lack of remote IP reachability, not local link status.
Depending on the kind of failure Ulysses is talking about, you can end up blockholing traffic using bonding.
If we prefer not buying a router or reflashing one or using a gateway VM, is there an easy way to do failover HA? Doesn't a package for it exist in ubuntu and derivatives?
I was talking about two things. One is a physical router. Two is a virtual router/firewall distro running in a virtual machine. It may be possible to run it locally. I used to know were the instructions were for a bsd set up that only did this redundant ISP to run in a vm. Can't find it just now. There was a bsd image vm already created for this task.
Editing /proc/sys/net/ipv4/route/gc_timeout to set it to 10 and then disabling networking from the gui of the network manager icon and then enabling it back on, and then typing this:
route add default gw 192.168.1.1 dev eth1
The result is this routing table:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1
192.168.0.0 * 255.255.255.0 U 1 0 0 eth0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth1
Looks alright but it does not work. You unplug the telephone cable, hit reload on the browser and the browser fails to connect after a timeout much longer than 10 seconds. Hitting reload again, same again, no connection occurs. What is wrong?
Because you're blackholing traffic into the default route which did not get removed on link-down.
If controlling the default route via interface state is what you're after and not distant IP connectivity,
then there are some examples on how to setup your interfaces file on this page:
If you disconnect the telephone cable like I did to simulate loss of distant connectivity, and not the ethernet cable that leads to the adsl router, doesn't the interface state stay the same?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.