Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Linux server running Debian which acts as a router/gateway for a network.
The server has 3 NICs on eth0 is the main ISP, on eth1 the backup ISP and on eth2 the network.
Is it possible to setup a script or something that will check if the connection with the main ISP is up and if not to switch(and setup the routes properly) to the backup ISP?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Please see the Linux Advanced Routing & Traffic Control documentation for "Routing for multiple uplinks/providers" here:

http://lartc.org/howto/lartc.rpdb.multiple-links.html

share|improve this answer

You may read http://serverfault.com/questions/25754/gateway-status-checking-methods-on-linux-bsd it's similar to what you are asking.
To answer you question precisely. You have normally 2 public IP address, one on eth0 and one on eth1.
You could write a script that try to ping the default gateway of isp1 (on eth0) and switch to eth1 if ping fail. But this will only switch when your link at your side is down (like DSL line down) but not from an outage within the ISP network because his gateway will still ping.
So you probably what to :

1.Ping ISP1 default gateway
2. Ping www.google.com or something else that is reliable
3. Check for paquet on eth0 with tcpdump 3.

If 1 is down, you should change the defaut gatway to the ISP2 gatway IP.
If 1 is Ok but 2 is Ko, may be it's juste google, may be an outage on ISP side, you may try other well know service yahoo.com, microsoft.com if all are Ko you probably want to switch to ISP2. You could use 3 here to see if you still receive packet from internet.

Depending on your distribution you have certainly some ifup/ifdown script somewhere in /etc they are called when an interface come up and down. This can also be used to switch the gateway. They will be called only when you lost the ethernet link.

share|improve this answer

How about doing this in the router?

The Draytek 2910 (ethernet) and 2820 (ADSL) routers support two WAN ports with load balancing and failover. The bit more expensive 3300 router supports 4 WAN ports.

JR

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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