DEV Community

IPYE
IPYE

Posted on

CARP Failover on OpenBSD for a Gateway Address in Your Free /48

Disclosure up front: I run IPYE, a company that leases IP space. Most of this article is practical how-to; IPYE appears where a free /48, LOA, or ROA helps you try the work, with a short call to action at the end.

A single gateway router is a single point of failure for every host behind it. OpenBSD's Common Address Redundancy Protocol, CARP, lets two routers share a virtual address: one holds it as master, and the other takes over within seconds if the master fails. Combined with pfsync for firewall state, it gives a LAN numbered from your own prefix a gateway that survives a router reboot. This guide sets up CARP on two OpenBSD routers for a LAN using 2001:db8:100:10::/64 from a free IPv6 /48 from IPYE.

The layout

  • gw1: LAN interface em1 with 2001:db8:100:10::2/64
  • gw2: LAN interface em1 with 2001:db8:100:10::3/64
  • shared gateway address: 2001:db8:100:10::1, held by whichever router is master
  • a direct cable between the routers on em2 for pfsync

Hosts on the LAN use 2001:db8:100:10::1 as their default gateway.

CARP interfaces

On gw1:

# /etc/hostname.carp10
vhid 10 carpdev em1 advskew 0 pass REPLACE_WITH_SHARED_SECRET
inet6 2001:db8:100:10::1 64
Enter fullscreen mode Exit fullscreen mode

On gw2, the same file with advskew 100:

# /etc/hostname.carp10
vhid 10 carpdev em1 advskew 100 pass REPLACE_WITH_SHARED_SECRET
inet6 2001:db8:100:10::1 64
Enter fullscreen mode Exit fullscreen mode

vhid identifies the virtual group and must match on both routers. advskew decides who becomes master: the router with the lower value advertises more often and wins. pass is a shared secret that authenticates CARP advertisements between the two routers; generate a long random value and use the same one on both.

Enable preemption so the preferred router takes the address back once it recovers:

echo net.inet.carp.preempt=1 >> /etc/sysctl.conf
sysctl net.inet.carp.preempt=1
Enter fullscreen mode Exit fullscreen mode

Apply the interface with sh /etc/netstart carp10.

pf rules

CARP advertisements use their own IP protocol. Allow them on the LAN interface, and allow pfsync on the dedicated link:

pass quick on em1 proto carp keep state (no-sync)
pass quick on em2 proto pfsync keep state (no-sync)
Enter fullscreen mode Exit fullscreen mode

Without the CARP rule, each router never hears the other's advertisements, and both become master, which causes duplicate address problems on the LAN.

pfsync for state

# /etc/hostname.pfsync0
syncdev em2
up
Enter fullscreen mode Exit fullscreen mode

pfsync copies firewall state between the routers, so existing connections continue after a failover instead of being dropped by the new master's firewall. Use a direct cable or a dedicated VLAN; pfsync traffic is not authenticated and should never cross an untrusted network.

Check the state

ifconfig carp10
Enter fullscreen mode Exit fullscreen mode

The output shows carp: MASTER on one router and carp: BACKUP on the other, along with the vhid and advskew. Reboot the master and watch the backup change to MASTER within a few seconds. When the original master returns, preemption hands the address back.

Hosts: use the virtual address as gateway

IPv6 hosts often learn their default router from router advertisements, which come from a router's own link-local address. If hosts use the physical routers' link-local addresses as gateways, CARP failover does not help them, because the old router's link-local address disappears with it. For servers on this LAN, configure the default gateway statically as 2001:db8:100:10::1, the CARP address. The new master answers neighbour discovery for it after a failover, and hosts keep forwarding to the same gateway address.

If you rely on SLAAC for clients, consider running router advertisements on both routers with the same prefix, so clients learn two default routers and fail over through their own neighbour unreachability detection, independent of CARP.

The upstream side

The LAN gateway is only half of the redundancy. Each router also needs a path to the Internet. If both routers announce the /48 to upstreams over BGP, the upstream side fails over through BGP while the LAN side fails over through CARP. If only one router has the upstream connection, CARP protects against the other router failing but not against the uplink failing.

Test it regularly

Schedule a failover test after each OpenBSD upgrade: demote the master with ifconfig carp10 advskew 200, confirm the backup takes over and that a long-running connection survives, then restore the setting.

The prefix both routers share

Hosts behind the CARP address use your /48, announced with the LOA from the IPYE portal and validated by the ROA that IPYE creates.

Next step

Claim your free /48, set up two OpenBSD routers with a shared CARP gateway address, and point your servers at it. Questions: ipye@turnel.com.

About IPYE

IPYE (https://ipye.com) leases IPv4, IPv6 and ASN space with instant setup. Your first IPv6 /48 is free for the first year, a real allocation you can announce on your own ASN, with a LOA from the portal and the ROA created automatically. ASN and region changes apply automatically. IPv4 /24 to /22 leases include LOA, ROA and per-/24 rDNS; WHOIS is editable on IPv6 /44 and larger. Locations: Los Angeles, New York, Ashburn, Salt Lake City, London, Amsterdam, Frankfurt. Claim your free /48: https://my.ipye.com/products/ipv6-rental. Questions: ipye@turnel.com.

Disclosure: I run IPYE

Top comments (0)