Skip to main content
RunBook Academy

LinuxLVI · Keepalived and VRRPVRRP

VRRP concepts - virtual router redundancy protocol

Foundation⏱ ~10 minkeepalived

What you'll learn

  • Describe VRRP and the virtual router concept
  • Explain master and backup roles
  • Recognise the election when the master fails
  • Use keepalived for VRRP on Linux

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

VRRP (Virtual Router Redundancy Protocol) provides high-availability for IP addresses. The classic use is floating an IP between two routers. This lesson covers the concept and the Linux implementation.

What VRRP does

VRRP allows multiple routers to share a virtual IP address. One router is the master; it holds the IP. If the master fails, a backup takes over.

Normal:
  Router A (master): holds 10.0.0.100
  Router B (backup): standby

After Router A fails:
  Router A: down
  Router B (now master): holds 10.0.0.100

The transition is not instantaneous, and it is not sub-second with the settings this course uses. A backup only declares the master down after the master-down interval: three missed advertisements plus a skew time derived from priority. With advert_int 1 and priority 100 that works out at roughly 3.6 seconds of VIP outage, during which established connections through the VIP are dropped.

You can shorten it — advert_int 0.5 brings the interval to about 1.8 seconds — but that is a trade, not a free improvement. Halving the interval doubles the sensitivity to transient packet loss, and a pair that flaps the VIP under momentary congestion is worse than one that takes an extra second to fail over.

Do not take 3.6 seconds on trust either. Measure it on your own pair, across a controlled failover, and record the result as the component’s real RTO:

# Substitute your own values before running:
VIP=10.0.0.100

ping -i 0.2 -D "$VIP"
# Then fail the master over. Count the gap in the timestamps:
# missed replies x 0.2s is your measured failover time.

VRRP packet

VRRP uses IP protocol 112 (multicast 224.0.0.18). The master advertises periodically; the backups listen.

When a backup stops hearing advertisements, it starts the election process. The highest-priority backup becomes the new master.

Priority

Each router has a priority (1-255, default 100). Higher is better. The master has the highest priority. When the master fails, the highest-priority backup takes over.

Manual priority changes can pre-determine which backup becomes the master.

Preemption

By default, VRRP preemption is enabled: when the original master comes back, it takes over. Disabling preemption (“nopreempt”) keeps the current master until it fails.

For maintenance, disable preemption. For automatic recovery, enable.

Use cases

  • Floating IP between two routers: classic VRRP.
  • Floating IP for a service: VRRP between two hosts running the service.
  • Gateway redundancy: VRRP on edge routers.

Limitations

  • Both routers must be on the same subnet (VRRP uses layer 2 multicast).
  • No authentication in VRRPv2 (use VRRPv3 or keepalived’s passwords).
  • No application-layer health checks in basic VRRP; use keepalived for that.

Knowledge check

Knowledge check · 3 questions

  1. Q1. What does VRRP do?

  2. Q2. All routers in a VRRP group have to sit on the same subnet.

  3. Q3. Which of the following are valid VRRP use cases? Select all that apply.

Passing score: 75%. Answers are checked in this browser.