UCARP on Debian 10

In this example I will show what is needed to create a UCARP fail-over IP on Debian 10. In this example my service is BIND9, but ofcourse you can change that to anything you require.

  • Run apt-get install ucarp
  • Edit interfaces via nano /etc/network/interfaces.
    Config should look somtething like this;
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
        address 192.168.0.212/24
        gateway 192.168.0.1
        ucarp-vid 11
        ucarp-vip 192.168.0.210
        ucarp-password password01
        ucarp-advbase 1
        ucarp-advskew 0
        ucarp-master no

iface eth0:ucarp inet static
        address 192.168.2.210
        netmask 255.255.255.0
  • mkdir /opt/ucarp
  • cd /opt/ucarp
  • Create the following 3 files;

start-ucarp (Match eth0, IPs and password to your situation)

#!/bin/bash
/usr/sbin/ucarp -i eth0 -s 192.168.0.211 -B -z -v 1 -p password01 -a 192.168.0.210 -u /opt/ucarp/vip-up -z -d /opt/ucarp/vip-down

vip-up (Match /24 to your subnet)

#!/bin/sh
/sbin/ip addr add ${2}/24 dev $1

vip-down (Match /24 and eth0 to your situation)

#!/bin/sh
/sbin/arptables -I INPUT -d $2 -j DROP
/bin/sleep 2 && /sbin/ip addr del $2/24 dev eth0
/sbin/arptables -D INPUT 1
  • Make all the files executable using: chmod +x /opt/ucarp/*
  • Create a service for ucarp using:
    nano /etc/systemd/system/ucarp.service
    that should look like this;
[Unit]
Description=ucarp Virtual IP Address Management
After=bind9.service

[Service]
Type=simple
ExecStart=/opt/ucarp/start-ucarp
RemainAfterExit=true
ExecStop=/usr/bin/killall -SIGTERM ucarp
ExecStop=/bin/sleep 10
TimeoutStopSec=30
StandardOutput=journal

[Install]
WantedBy=multi-user.target
  • systemctl daemon-reload
  • systemctl enable ucarp.service
  • Reboot the system for the settings to take effect.

You should be able to run service ucarp status to see the effect of the settings and also the current state of the machine;

Mar 03 13:58:57 dns02 systemd[1]: Started ucarp Virtual IP Address Management.
Mar 03 13:58:57 dns02 ucarp[356]: [INFO] Local advertised ethernet address is [00:11:22:33:44:55] 
Mar 03 13:58:57 dns02 ucarp[356]: [WARNING] Switching to state: BACKUP 
Mar 03 13:58:57 dns02 ucarp[356]: [WARNING] Spawning [/opt/ucarp/vip-down 

Leave a Reply

Your email address will not be published. Required fields are marked *