LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2016, 05:25 AM   #1
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Rep: Reputation: 57
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.

Last edited by Ulysses_; 07-09-2016 at 05:29 AM.
 
Old 07-09-2016, 09:10 PM   #2
jnihil
Member
 
Registered: Dec 2012
Location: inside the matrix
Distribution: Debian, Xubuntu, Gentoo, Antergos
Posts: 90

Rep: Reputation: 27
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?).
 
Old 07-10-2016, 05:37 AM   #3
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
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.

Last edited by Ulysses_; 07-10-2016 at 05:56 AM.
 
Old 07-10-2016, 06:14 AM   #4
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
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?
 
Old 07-10-2016, 06:56 AM   #5
jnihil
Member
 
Registered: Dec 2012
Location: inside the matrix
Distribution: Debian, Xubuntu, Gentoo, Antergos
Posts: 90

Rep: Reputation: 27
I think the syntax differes on distro/versions, but and example would be:

sudo route del default gw 192.168.0.1 dev eth0
sudo route add default gw 192.168.1.1 dev eth1

manpage for route command should clarify any differences in syntax.
 
Old 07-10-2016, 07:01 AM   #6
jnihil
Member
 
Registered: Dec 2012
Location: inside the matrix
Distribution: Debian, Xubuntu, Gentoo, Antergos
Posts: 90

Rep: Reputation: 27
Quote:
Originally Posted by Ulysses_ View Post
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.
 
Old 07-10-2016, 05:04 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,877

Rep: Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615
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.
 
Old 07-10-2016, 05:12 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,461

Rep: Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828
I assume jefro is talking about channel bonding.

http://www.tecmint.com/ethernet-chan...linux-systems/
 
Old 07-10-2016, 07:08 PM   #9
jnihil
Member
 
Registered: Dec 2012
Location: inside the matrix
Distribution: Debian, Xubuntu, Gentoo, Antergos
Posts: 90

Rep: Reputation: 27
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.
 
Old 07-10-2016, 08:35 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,461

Rep: Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828Reputation: 5828
Indeed.
 
Old 07-11-2016, 01:42 AM   #11
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
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?
 
Old 07-11-2016, 04:19 PM   #12
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,877

Rep: Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615Reputation: 3615
I wasn't talking about bonding.

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.

http://lartc.org/howto/lartc.rpdb.multiple-links.html
http://serverfault.com/questions/312...m-a-second-isp
https://www.linux.com/news/using-linux-failover-router
 
Old 07-11-2016, 07:51 PM   #13
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
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?

Last edited by Ulysses_; 07-11-2016 at 07:52 PM.
 
Old 07-11-2016, 08:23 PM   #14
jnihil
Member
 
Registered: Dec 2012
Location: inside the matrix
Distribution: Debian, Xubuntu, Gentoo, Antergos
Posts: 90

Rep: Reputation: 27
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:

http://askubuntu.com/questions/16803...-ubuntu-server
 
Old 07-11-2016, 09:03 PM   #15
Ulysses_
Senior Member
 
Registered: Jul 2009
Posts: 1,303

Original Poster
Rep: Reputation: 57
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Network Bridge Blocking Switch/Internet Access almcneill Linux - Networking 3 08-31-2011 07:46 PM
Ubuntu 8.04 in mixed Mac & Windows network Internet access but no access to network. traveller7 Linux - Networking 1 01-10-2009 08:53 PM
Network and P2P with Marvell Yukon adapters (or internet slows down) fraz Linux - Hardware 0 05-24-2005 03:43 PM
Automatically switch to different wireless network? m_a_b Linux - Wireless Networking 0 10-07-2004 10:12 AM
Easy access to the Internet drabkin Linux - Newbie 10 11-26-2002 09:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration