Commands / Services and tunnels

Services and tunnels

keepalived

Also VRRP, virtual IP, VIP, FHRP, first-hop redundancy, keepalived.conf

Runs VRRP on Linux: routers sharing a virtual gateway address, one master holding it at a time.

Each vrrp_instance in /etc/keepalived/keepalived.conf is one VRRP group: the card it runs on, the virtual_router_id, the router's priority, how often the master advertises (advert_int) and the virtual_ipaddress it holds. use_vmac puts the address on a macvlan card (vrrp.<VRID>) with the virtual MAC 00:00:5e:00:01:<VRID>; track_interface lowers the priority when another card fails; nopreempt keeps a returning higher-priority router in backup. Watch it work with ip -br addr (who holds the address) and tcpdump -v vrrp (who advertises, with which priority).

keepalived command usage

keepalived [options]
kill -HUP $(cat /run/keepalived/keepalived.pid)

Options

-n / --dont-fork
stay in the foreground
-l / --log-console
log to the terminal, not only syslog
-D / --log-detail
log every state change in detail
-f FILE
read another configuration file
kill -HUP
reread the configuration without stopping

keepalived examples

keepalived
Starts keepalived in the background with /etc/keepalived/keepalived.conf.
kill -HUP $(cat /run/keepalived/keepalived.pid)
Makes keepalived reread its configuration after an edit.
ip -br addr show vrrp.1
Shows whether this router holds the virtual address of VRID 1: it is master if it does.
tcpdump -nn -e -v -i eth0 vrrp
Shows the master's advertisements: virtual MAC, VRID, priority and virtual address.
pkill keepalived
Stops it cleanly: the master resigns with a priority-0 advertisement and the backup takes over at once.

Pitfalls

  • Routers elect only within one virtual_router_id: a mismatch makes two groups, each with its own master, both claiming the address.
  • A master whose uplink fails stays master unless the group tracks that uplink (track_interface).
  • keepalived wants the card's own name (eth0), not an alternative name.

Run it on real machines

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Start with a free account: Google or email, no card.

Open this lab