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: 10.200.0.200:
$ cat /etc/network/interfaces auto eth0 iface eth0 inet static address 10.200.0.102 netmask 255.255.255.0 ucarp-vid 3 ucarp-vip 10.200.0.200 ucarp-password ourpassword ucarp-advskew 10 ucarp-advbase 1 ucarp-master yes iface eth0:ucarp inet static address 10.200.0.200 netmask 255.255.255.255
You can now restart your network:
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 10.200.0.102/24 brd 10.200.0.255 scope global eth0 inet 10.200.0.200/32 brd 10.255.255.255 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.