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 Debian Wheezy server running Xivo (let's call it A), this server has 2 interfaces: eth0 and eth1 . There is no default gateway and only a few servers are statically reached from A. eth0 has a public IP and connects directly to a remote server (let's call it B), the second interface of A, eth1 is on a local network with another internet connection supposed to be used for different purpose.

In the routing table A, B is reachable through interface eth0. What I want is to set up a failover route that tries to connect through eth1 if the connection attempt fails on eth0. I have no access to the routers, and no dynamic routing from outside A can be involved.

So far I see different stuff like ip rule, heartbeat HA and other technologies but with this question, what I want to achieve is to determine if what I want to do is possible and if possible with what kind of technologies.

EDIT 1

I decided to rephrase my question because I feel like no one knows.
How can I monitor a link from one server to another and take action if the link is down? It can also be related to the arp resolution because I'm virtually connected to the remote host and I know its MAC address.
I'm pretty sure there are already possibilities out in the jungle of the Internet, and I don't want to reinvent the wheel for that task.

EDIT 2

As the solution of the script is finally what I chose I'll accept it and reward it, but I added a sort of compilation of all I tried before using the script

share|improve this question

migrated from unix.stackexchange.com Jun 28 at 11:09

This question came from our site for users of Linux, FreeBSD and other Un*x-like operating systems..

    
Need some more information. Are these connections from different ISPs? How are you planning on managing IP addresses? Are you only trying to address outbound routes? In my opinion, you really should just setup a bridged connection with an ISP that uses BGP. –  Devon Jun 30 at 5:40
    
@devon the first connection is sdl for voip with bandwidth warraty, the second is a cheap ADSL used for any other internet connection, in this case selling a BGP connection to the client is not an option –  Kiwy Jun 30 at 5:44
    
what about my other questions. Is there a reason why you are not using colocation in a datacenter? DSL lines really shouldn't be used for servers. There is a reason why colo is available. Hosting a server in a datacenter gets you access to proper environments for a server, proper connectivity, and proper redundancy before it gets to your server. –  Devon Jun 30 at 5:49
    
Contracts and business operationnal... @Devon –  Kiwy Jun 30 at 6:04
    
Okay, I'm assuming you're only trying to handle outbound connections from this server based on the description of your problem. How are you connecting to the second server? Are you using SSH, another protocol? –  Devon Jun 30 at 6:11
show 1 more comment

4 Answers 4

up vote 2 down vote accepted
+100

I had a similar problem some time ago in reaching a remote server from a datalogger (Ubuntu) through an unstable HDSL connection (sometimes not working for days!). I've created a simple bash script running on the datalogger in crontab. The script worked like this:

  • test the status of HDSL pinging a public/always available server (like a DNS or something of sort)
  • if the test was KO, the script added a route to the remote server through a backup 3G router on the same network
  • if the test was OK, the previous route was removed making the datalogger reach the remote server through the HDSL router

It was not a refined solution but it worked in my scenario!

share|improve this answer
    
I'm very surprised nothing else exists... –  Kiwy Jun 29 at 19:29
add comment

The following article explains how you can achieve fail over routing in a simple fashion.

http://archive09.linux.com/feature/113988

This involves adding two routes to the same destination, one via eth0 and one via eth1, and a time out setting that switches the active route when one becomes unavailable.

Bear in mind that the source IP of outbound packets will change if nat is used. With connectionless protocols, such as HTTP, this will not matter. However, with connection orientated protocols the route may switch over, but connections will fail if the source IP changes.

VoIP is mentioned in your comments and you should expect to see calls fail and need to be restarted.

share|improve this answer
    
this article I already read, mention failover if an eth interface goes down, which is not what I want to really monitor, thank though for the search –  Kiwy Jun 30 at 9:52
add comment

Your question is interesting. A google search gaves Mpath-tools

Mpath-tools is a set of programs for linux 2.6+ that aim to facilitate load balancing and failover over multiple and heterogeneous ISP connections.

Mpathd is a daemon and the core of mpath-tools, it runs in the background, monitoring the state of each connection. It dynamically update routing tables according to the state of the gateways and a set of rules set by the administrator.

The state of each connection is determined by sending through ICMP probes to one or more addresses.

I never tried it.
This is a confidential project, they are not well indexed, "Linux static route failover" search didn't gave anything, and "Linux Dynamic route failover" gave the site in page 4 (perhaps my search skills are not good); even "mpath-tools" returns only a few links. Note that it doesn't means that it isn't working.

share|improve this answer
add comment

I end up with several solution and the one being retain is the "crontabed" script running with an arping this is the script:

#!/bin/sh

#remote host to test on public interface
REMOTE_TEST_IP="195.168.156.1"
REMOTE_TEST_MAC="00:2D:FF:FF:FF:FF"

#number of arp request send to test connectivity
TEST_COUNT=4

#the rate acceptable of arp request failling, strictly above this rate the route will be change
#NEVER put 100 or it will never set up failover
ACCEPTABLE_FAILURE_RATE=20

#list of network that will be rerouted if test fails
NETWORK_LIST="95.140.0.0/20 195.28.200.40/32 217.15.80.0/20"

PUBLIC_DEVICE="eth0"
PUBLIC_GATEWAY="192.168.1.250"

PRIVATE_DEVICE="eth1"
PRIVATE_GATEWAY="195.168.156.5"

#try to ping the remote host ip and the remote host mac, extract the result line and get the failure rate
FAILURE_RATE=$(arping -i $PUBLIC_DEVICE -c $TEST_COUNT -t $REMOTE_TEST_MAC $REMOTE_TEST_IP | grep % | sed -r s/.* ([0-9]{1,3})% .*/\1/)



#if the faillure is superior to the acceptable failure rate, change the route to remote the remote host
if [ $FAILURE_RATE -gt $ACCEPTABLE_FAILURE_RATE ]
then

  for NETWORK in $NETWORK_LIST
  do
    logger "$0 - WARNING -The network route to $NETWORK_LIST are set to failover route."
    route del -net $NETWORK gw $PUBLIC_GATEWAY dev $PUBLIC_DEVICE
    route add -net $NETWORK gw $PRIVATE_GATEWAY dev $PRIVATE_DEVICE
  done

else

  for NETWORK in $NETWORK_LIST
  do
       #back to default route
       route del -net $NETWORK gw $PRIVATE_GATEWAY dev $PRIVATE_DEVICE
       route add -net $NETWORK gw $PUBLIC_GATEWAY dev $PUBLIC_DEVICE

  done
fi

I also found different solution like mention in the other answers.

  • MPath-tool the installation process mention a php script which doesn't sound really reliable
  • Link Status Monitor, maintain only for redhat based system

I do not really know any other solutions, the blog mention by John Auld here is dated from 2005 when linux was still using metric of the route which is no longer the case except if you use a dynamic routing protocol.

share|improve this answer
add comment

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.