Operations 7 min read

Configure Keepalived Dual‑Host Mode for Automatic VIP Failover

This guide demonstrates how to set up a two‑node Keepalived configuration in dual‑host mode, creating two VRRP instances that act as master and backup to enable seamless VIP address migration between the servers.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Configure Keepalived Dual‑Host Mode for Automatic VIP Failover

Overview

The article explains a Keepalived dual‑host (master‑master) setup that demonstrates VIP address movement. Two servers (ka1 and ka2) run Keepalived with two VRRP instances, each acting as master for one virtual router and backup for the other.

Environment

ka1 and ka2 are two separate Keepalived servers.

Each server hosts a virtual router with two VRRP instances that are master/backup of each other.

ka1 Keepalived Configuration

yum install -y keepalived
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1
   vrrp_mcast_group4 224.100.100.100 
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 66
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        172.16.0.100/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 88
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 654321
    }
    virtual_ipaddress {
        172.16.0.200/24 dev ens33 label ens33:2
    }
}

cat /etc/hosts
10.0.0.125 ka1
10.0.0.126 ka2
ssh-keygen
ssh-copy-id 10.0.0.126

ka2 Keepalived Configuration

yum install -y keepalived
cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
   [email protected]
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1
   vrrp_mcast_group4 224.100.100.100 
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 66
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        172.16.0.100/24 dev ens33 label ens33:1
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 88
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 654321
    }
    virtual_ipaddress {
        172.16.0.200/24 dev ens33 label ens33:2
    }
}

cat /etc/hosts
10.0.0.125 ka1
10.0.0.126 ka2
ssh-keygen
ssh-copy-id 10.0.0.125

Verification – Observe VIP Migration

Start Keepalived on ka1:

systemctl start keepalived
ip a

Both VIPs (172.16.0.100 and 172.16.0.200) appear on ens33 of ka1.

Start Keepalived on ka2:

systemctl start keepalived
ip a

Now ka2 becomes MASTER for VI_2 and takes over the VIP 172.16.0.200, while ka1 retains VIP 172.16.0.100.

VRRP Multicast Advertisement Capture

tcpdump -i ens33 -nn host 224.100.100.100

The capture shows VRRP advertisements from both servers with their respective virtual router IDs and priorities, confirming the failover behavior.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Operationshigh availabilityVRRPLinux networkingkeepalived
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.