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.
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.126ka2 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.125Verification – Observe VIP Migration
Start Keepalived on ka1:
systemctl start keepalived
ip aBoth VIPs (172.16.0.100 and 172.16.0.200) appear on ens33 of ka1.
Start Keepalived on ka2:
systemctl start keepalived
ip aNow 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.100The capture shows VRRP advertisements from both servers with their respective virtual router IDs and priorities, confirming the failover behavior.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
