Skip to main content
RunBook Academy

OPNsenseXXVII · CARPCARP fundamentals

CARP concepts and VHIDs — the protocol that makes a shared IP work

Intermediate⏱ ~13 minifconfigsysctltcpdump

What you'll learn

  • Explain what CARP is and why two firewalls need a shared IP address
  • Describe the role of the Virtual Host ID (VHID) and the CARP password
  • Read the base advertisement skew and the default one-second advertisement interval
  • Identify the three CARP states — master, backup, init — and what each means
  • Recognise CARP as a FreeBSD contribution shared with OPNsense, not VRRP

Prerequisites

Verified against OPNsense 25.x · FreeBSD 14.x · PF (FreeBSD packet filter) FreeBSD 14.x · Unbound 1.20+ · Kea DHCP OPNsense 25.x plugin · WireGuard in-kernel + OPNsense plugin · strongSwan (IPsec plugin) OPNsense 25.x plugin · OpenVPN 2.6.x · Suricata 7.x · 2026-08-14

Not yet marked complete on this device.

Two firewalls in HA need to share one IP address. The LAN hosts, the upstream routers, and every Internet destination see a single gateway. They do not know — and must not be able to tell — whether OPNsense-A or OPNsense-B is actually answering. The protocol that lets one of them claim the IP at any moment, and lets the other take over if the first one disappears, is CARP — the Common Address Redundancy Protocol.

This lesson covers what CARP is at the protocol level, what a Virtual Host ID (VHID) identifies, what the base advertisement skew controls, and how the master is elected. The next lessons cover the advertisement packet, the configuration in OPNsense, the multicast behaviour, the failover triggers, and the troubleshooting.

The problem CARP solves

A LAN host has a default gateway configured to one IP — say 192.0.2.1. If the firewall owning that IP fails, the host keeps sending frames to the same MAC it learned from ARP for 192.0.2.1. Until something tells the host that 192.0.2.1 is now somewhere else, the host cannot reach the Internet. The recovery time without a protocol is the time for the host’s ARP entry to age out (minutes on FreeBSD, 20 minutes default) plus the time for the backup to send a gratuitous ARP.

CARP makes the recovery time independent of the host’s ARP timeout. The firewalls coordinate among themselves: one holds the IP, the other is ready, and the secondary takes over and sends a gratuitous ARP within a second of failure. The host re-ARPs the gateway — or accepts the gratuitous ARP — and traffic resumes.

The protocol is small but precise. Each firewall on the shared segment advertises its presence on a multicast group, with a virtual host identifier, a base advertisement skew, and an advertisement interval. The firewall with the lowest effective skew becomes the master; the other becomes the backup. The backup watches for the master’s advertisements and takes over when they stop.

VHID and the virtual IP

CARP groups nodes by a Virtual Host ID — a number from 1 to 255. Each VHID identifies one shared IP (one virtual IP, one VIP) on one segment. Two firewalls in the same VHID on the same network are competing for the same VIP. Two different CARP groups (VHID 1 on LAN, VHID 2 on WAN) are independent — a node can be master on one and backup on the other.

The VHID is what the advertisements carry. When a node advertises on the segment, the packet includes the VHID, the source IP of the node (the physical IP, not the shared IP), the base skew, and the advertisement interval. Other nodes on the segment listen to the multicast and update their view of who is master for each VHID.

The CARP password is a pre-shared secret (up to 20 characters) carried in the advertisement packet. It is not a strong authentication mechanism — it is a typo check. Two firewalls with the same VHID and different passwords will not see each other as peers; both will declare themselves master. The result is the classic split-brain: two masters, both answering ARP for the VIP, and the LAN seeing inconsistent frames.

Read-only / Safeifconfig igb1
$ ifconfig igb1
igb1: flags=8963<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
      ether aa:bb:cc:11:22:33
      inet 192.0.2.2 netmask 0xffffff00 broadcast 192.0.2.255
      inet 192.0.2.1 netmask 0xffffff00 broadcast 192.0.2.255 vhid 1
      media: Ethernet autoselect (1000baseT <full-duplex>)
      status: active
      carp: MASTER vhid 1 advbase 1 advskew 0

Illustrative output

Base advertisement skew and the election

The election is “lowest effective skew wins”. Each node has a base advertisement interval (advbase, default 1 second) and a base advertisement skew (advskew, default 0). The effective advertisement interval is advbase + (advskew / 256) seconds. With advbase=1 and advskew=0, the node advertises every 1.000 seconds. With advbase=1 and advskew=100, the interval is 1.391 seconds, and the node is the “slower” advertiser.

The node with the shorter interval is the master. Two nodes both configured with advskew=0 will tie — both will claim master, and the protocol’s tie-break behaviour may flap. The OPNsense convention is to set the primary to advskew=0 (or advskew=10 for a small preference) and the secondary to advskew=100 or higher. The result is a deterministic, stable election.

The backup watches for the master’s advertisements. If three consecutive advertisements are missed (the default — configurable), the backup declares the master gone, becomes the master itself, and sends a gratuitous ARP on the segment to update the switches’ MAC tables. The total failover time is 3 × advbase plus the gratuitous ARP time — 3 seconds with the default advbase=1.

The three CARP states

Each CARP interface on each node is in one of three states at any moment:

  • INIT. The interface is up but the node has not yet heard from any peer (or has not yet started advertising). This is the state on a freshly booted node before the first advertisement.
  • MASTER. The node is advertising on the segment and is the rightful owner of the VIP. It responds to ARP requests for the VIP and accepts frames sent to the VIP’s MAC.
  • BACKUP. The node is advertising on the segment but has heard from a peer with a lower effective skew. It does not respond to ARP for the VIP and silently discards frames sent to the VIP’s MAC.

The state changes are event-driven. A backup transitions to master when the master’s advertisements stop. A master transitions to backup when it sees a peer with a lower effective skew (only possible if the operator reconfigured skew on the live system). The INIT state is usually transient — a node in INIT for more than a few seconds has either lost its network or has its CARP daemon stopped.

Read-only / Safesysctl net.inet.carp
$ sysctl net.inet.carp
net.inet.carp.allow: 1
net.inet.carp.preempt: 1
net.inet.carp.dscp: 56
net.inet.carp.log: 1
net.inet.carp.demotion: 0
net.inet.carp.ifdown_demotion_factor: 240
net.inet.carp.senderr_demotion_factor: 240

Illustrative output

Summary

  • CARP is the native FreeBSD/OpenBSD protocol that lets two firewalls share one IP. OPNsense uses CARP, not VRRP.
  • A VHID identifies one shared IP on one segment. The VHID is carried in the advertisement and the password authenticates peer advertisements.
  • The master is the node with the shortest advertisement interval (advbase + advskew/256 seconds). Default is one advertisement per second with skew 0 on the primary, skew 100 on the secondary.
  • The three states are INIT (transient), MASTER (owns the VIP), and BACKUP (watching for the master). Transition from BACKUP to MASTER happens after three missed advertisements.
  • The most common split-brain cause is a mismatched CARP password.

Knowledge check · 5 questions

  1. Q1. Why does a deployment need a protocol like CARP rather than just advertising the shared IP from both firewalls with gratuitous ARP?

  2. Q2. CARP and VRRP are interoperable on the same network segment.

  3. Q3. Which of the following are carried in a CARP advertisement? Select all that apply.

  4. Q4. A primary firewall has advbase=1 and advskew=0. A secondary has advbase=1 and advskew=100. Which is the master, and what is the secondary's effective advertisement interval?

  5. Q5. A CARP node in BACKUP state silently discards frames sent to the VIP's MAC.

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