IP failover with Ucarp on Ubuntu

Mar 16, 2010  

Ucarp is an implementation of Common Address Redundancy Protocol (CARP) allowing failover of a single Virtual IP (VIP) for high availability.

In order to install ucarp:

apt-get install ucarp

You can find more about ubuntu’s integration of ucarp in /usr/share/doc/ucarp/README.Debian.

We’ll now modify /etc/network/interfaces to add our virtual IP:

$ cat /etc/network/interfaces
auto eth0
iface eth0 inet static
        ucarp-vid 3
        ucarp-password ourpassword
        ucarp-advskew 10
        ucarp-advbase 1
        ucarp-master yes

iface eth0:ucarp inet static

You can now restart your network:

/etc/init.d/networking restart

And you can check that your virtual IP is there:

$ ip a show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:26:b9:f9:48:d0 brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
    inet brd scope global eth0:ucarp
       valid_lft forever preferred_lft forever

On your second server you can do the exact same steps, except that you can set ucarp-master to no.

After you have restart the network on the second server the virtual IP won’t be there, you can try rebooting the first server and check that the virtual IP appears on the second server.

In the mean time you can ping the virtual IP to check that the failover works properly.

When the first server will be up again, the virtual IP will go back to this server as it is the master.