# [Mini howto] Failover internet setup with Perl daemon

## maiku

I've been working on a failover project using iproute2 to allow two internet connections (dual connections) to either be load balanced or just strictly failover.  Right now a Perl script gets forked into the background via an init script.  The Perl script also sets up the routes after the interfaces are initialized.  Any suggestions/commets/etc are appreciated.  I have not seen this setup on this forum yet, but if they are I apologize in advance for reinventing the wheel.

The script download: http://www.mikealeonetti.com/files/failover

Configurations:

/etc/conf.d/net *Quote:*   

> modules=( "iproute2" )
> 
> config_eth0=( "10.1.1.34/24" )
> 
> config_eth1=( "192.168.2.77/24" )

 In the kernel config: *Quote:*   

> CONFIG_IP_ADVANCED_ROUTER=y
> 
> CONFIG_IP_MULTIPLE_TABLES=y
> 
> CONFIG_IP_ROUTE_MULTIPATH=y

 /etc/iproute2/rt_tables *Quote:*   

> #
> 
> # reserved values
> 
> #
> ...

 /etc/init.d/multinet *Quote:*   

> #!/sbin/runscript
> 
> # Copyright 1999-2009 Gentoo Foundation
> 
> # Distributed under the terms of the GNU General Public License v2
> ...

 /etc/resolv.conf *Quote:*   

> # Opendns.com nameserver
> 
> nameserver 208.67.222.222

 

The idea is to download the script to /usr/local/bin/failover and set the options in the script.  You'll notice that there are variables in the script that need to be modified.  The script will fork itself into the background.  Just make sure "multinet" is run at startup (eg rc-update add multinet default).  If anything is unclear, again, please let me know

Original resources:

http://www.gentoo-wiki.info/Dual_internet_connections

http://blog.taragana.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/

Update 11/10/2010

The updates for this howto I am maintaining on http://www.mikealeonetti.com/wiki/index.php/Perl_Internet_failover_script

----------

## VinzC

What about bonding? I've been using bonding for quite a while now and it's perfect at automatic failover and dual connection. Unless I missed something.

----------

## maiku

Will bonding allow you to use two different IPs and Gateways?

----------

## VinzC

 *maiku wrote:*   

> Will bonding allow you to use two different IPs and Gateways?

 

Yes... and no. You may set two IP addresses to the bonding interface but not to slaves. You might try the former as well, I think it should work since ARP should take care through what interface to send packets. There's a problem if both addresses are sent by a DHCP server. In the latter case, bonding won't be possible.

----------

## maiku

Well, if bonding notices when one connexion is down and exclusively uses the other until the preferred one is back up then there really is no difference.  When I first started using the plain load balancing setup, the problem I had was that it would not notice when one connexion was down.  Sure it would work half the time because the other connexion was up, but it still tried to use connexion 1 and connexion 2.  If that problem doesn't exist with bonding then great.

----------

## VinzC

That problem doesn't exist with bonding I confirm that. I've been using bonding between eth0 and wlan0 with success for quite a few months now. For instance, when I want to use eth0 (gigabit) I make it the active slave. The system automatically switches to wlan0 when I unplug the cable. But bonding can also work with simultaneous multiple links, I think.

----------

