multihomed-ha is a perl script which can switch to a backup link in case the primary one goes down. When the primary link comes back online, it will switch back to the primary link.

Everytime a change in the routing table occurs, the script can optionally send a mail to the sysadmin.

By default the script runs as a daemon.


Project home page:

Luca Gibelli (nervous -at- bitchx -dot- it)

Personal home page:


You can grab the latest version at:

Visit the SourceForge project page at


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public Licence as published by the Free Software Foundation.
For full terms see the file COPYING.


multihomed is a perl script which can detect when your primary Internet uplink goes down and switch to a backup uplink. It's smarter than many similar scripts: it continuosly ping several hosts around the Internet using both uplinks and elects the best one as primary.

You can define the priority with which uplinks are tried. This can be very useful if you have a per-traffic contract on one of your uplinks and a flat-traffic contract on another one: you can configure multihomed to use the per-traffic uplink only if the other one is not working.

Many firewalls block ICMP packets, multihomed can cope with them because it sends a single SYN to a particular TCP service running on a host and checks if it gets an ACK back. This is very bandwidth efficient because SYN/ACK are really small packets. Thus you can test both uplinks quite often without the risk of consuming too much bandwidth.

multihomed runs as a daemon, you can define the interval between consecutive checks.

multihomed is better than other similar scripts because it can detect failures in your ISP's uplinks too! By checking multiple remote hosts around the Internet you can tell if your ISP is fully working or not. This is much more reliable than simply pinging a single server or (worse) your default router.

multihomed is very flexible: you can easily customize the commands to execute whenever one of the links goes down.


The first version of multihomed was released to the public on March 15th, 2005 after a short period of production use which gave good results.
See the file ChangeLog for the list of changes since then.


multihomed requires:


Conf. vars are at the beginning of the script. Most options are self explaining:

$DEBUG:         if set, the script won't go into background and will print some
                useful information to STDOUT

$notify_sender: From: field of notification emails

$notify_dest: To: field of notification emails

$smtp_host: smtp server used to send emails

$lockfile: path to the pid file for the daemon

$service_check: which tcp service to check (e.g. http -> port 80, ftp -> port 21...)

$sleep: how long to sleep between checks

$up_percent: success rate above which the link is considered up

$local_if:      each interface identifies one link. Traffic originating from
                a particular interface is routed through the corresponding uplink.
                We can test each link without touching the default
                route by setting the source ip address.
                "name" is an easy-to-remember name for the uplink
                "ip" is the ip address of the interface

@hostlink:      an array of hosts to which we will send syn packets. The
                port defined by $service_check must be open on these


Suppose you have 2 uplinks going through isp1 and isp2.

# ip route add default via $ROUTER1 table isp1

# ip route add default via $ROUTER2 table isp2

# ip route add default via $ROUTER1

# ip rule add from $LOCALIP1 table isp1

# ip rule add from $LOCALIP2 table isp2

For more information:


I failed to find a program that could:

  1. use something other than ICMP to verify connectivity and at the same time save resources by avoiding a full three way handshake.
  2. try to contact multiple hosts with both uplinks at the same time and select the uplink that works best. The approach of multihomed is more reliable and it's not limited to 2 uplinks.