jak@trace:~$ packet-trace

· 7 sections · boots in 6m 28s

Hub and spoke with VyOS and UniFi: from BGP to OSPF, and the things that bit me

Building a multi-site VPN with VyOS doing the tunnels and UniFi gateways staying in charge of the LANs. Why I swapped BGP for a single OSPF area, and four lessons the network taught me the hard way.

I’ve been building a site-to-site VPN for a handful of sites that each already had a UniFi gateway (UDM Pro or SE) running the show. Two hubs, one preferred and one backup, and a growing list of spokes, with plenty more to come. Some spokes have dual WAN, some sit behind CGNAT, and none of them were going to get UniFi Site Magic. This is how it’s put together, why the routing changed halfway through, and the bits that bit me.

The shape of it

The UDM stays the default gateway for every client VLAN. I didn’t want to rip that out. Next to it, on Proxmox, each site gets a VyOS VM that lives on its own transit VLAN and does nothing but tunnels and routing.

  • Route-based IPsec with VTIs. Every spoke builds a tunnel to both hubs, and the hubs have a tunnel between them.
  • The hub VyOS boxes sit behind their UDM’s NAT, so each UDM forwards UDP 500/4500 to its VyOS. Spokes behind CGNAT simply initiate outbound with NAT-T.
  • Every spoke gets its own PSK and its own IKE identity. The hubs use names rather than IPs as IKE IDs.
  • Tunnel and loopback addressing comes out of a dedicated block in 172.30.x. 10.0.0.0/8 is reserved for real site VLANs and nothing infrastructure is allowed in there.
  • Each VyOS gets a loopback on a dummy interface for management, with SSH listening only there and an input filter that only lets the IT VLANs in.
  • Inter-site traffic is never NATed. Internet traffic leaves through each site’s own UDM.

One early gotcha worth stating up front: pings across the first tunnel worked, SSH worked, but anything bulky stalled. A don’t-fragment ping at 1300 bytes went through and 1472 vanished without a trace. A textbook PMTU black hole. Every VTI now gets mtu 1400 and ip adjust-mss clamp-mss-to-pmtu, and a 1372-byte don’t-fragment ping now goes straight through.

BGP, then OSPF

The first version used BGP: iBGP between the hubs, eBGP from each spoke, local-pref to keep the preferred hub preferred. On top of that, every UDM needed static routes pointing remote prefixes at its VyOS, plus floating blackholes on VyOS so a dead tunnel didn’t turn into a routing loop between the UDM and VyOS.

It worked. It was also a lot of moving parts per site, and adding a spoke meant touching both hubs’ BGP and every UDM’s static routes.

UniFi can do OSPF, so I moved the lot to one OSPF area 0 across every site:

  • Each UDM forms an adjacency with its VyOS over the transit VLAN and advertises its LAN networks as passive interfaces. It never advertises a default route.
  • VyOS runs OSPF point-to-point on every VTI, plus its loopback as passive.
  • No redistribution anywhere. Default routes, blackholes, NAT and the odd breakout /32 stay out of OSPF.
  • Costs do the steering: 10 to the preferred hub, 100 to the backup and between hubs. A spoke reaches another spoke via the preferred hub at cost 20, and if that hub goes away everything shifts to the backup.

The migration ran with no outage because of administrative distance. eBGP (20) and UDM statics (1) beat OSPF (110), so I built OSPF underneath, checked every adjacency was Full and every prefix was present, then removed BGP and the statics one at a time and watched each route flip to “known via OSPF”. Rollback at any point was just putting a static back.

Two things to accept with OSPF. First, there’s no per-spoke prefix filtering like BGP gave me, so every subnet ticked into OSPF has to be unique across all sites. One site had to move its UniFi Default network off 192.168.1.0/24 for exactly that reason. Second, if the hub-to-hub tunnel dies, hub-to-hub traffic will happily transit a spoke. Resilient, but it uses a spoke’s WAN.

Small UniFi notes from doing it for real: the per-interface options (passive, cost, MD5, timers) only appear after you add the area, and no firewall policy was needed for OSPF itself. On VyOS, reset ip ospf process isn’t a thing; it’s sudo vtysh -c "clear ip ospf process".

Lesson one: a clean reboot is worse than a crash

I rebooted the preferred hub to prove failover. The spoke moved to the backup hub, as it should. Then the preferred hub came back and the spoke… stayed on the backup.

Dead peer detection only covers a peer that goes silent. A hub that reboots politely sends an IKE DELETE first, and with close-action left at its default of none, the spoke takes that as “fine, we’re done” and never tries again.

set vpn ipsec ike-group SPOKE-IKE close-action 'start'

With that on the spoke, a reboot retest reconnected to the preferred hub by itself. Any ike-group that initiates now gets DPD restart and close-action start together.

Lesson two: UDMs won’t forward to an IP that isn’t local

A cloud-hosted CCTV app needed to reach a camera at one of the spokes on TCP 7447. That had been handled by a little socat relay VM, which I wanted gone. The obvious fix was a port forward on the hub UDM straight to the camera’s IP across the VPN.

The UDM accepted that rule and then silently dropped every packet. A forward to an address that isn’t on one of its own networks just doesn’t go anywhere.

So the UDM forwards to the hub VyOS on the transit VLAN instead, and VyOS does the work:

  • DNAT 7447 to the camera’s real address.
  • SNAT to the hub’s loopback, on both the direct tunnel and the hub-to-hub tunnel, so return traffic comes back the same way whichever path is live.
  • The spoke UDM allows exactly that loopback as the source.

The forward on the hub UDM is locked to the CCTV app’s list of source IPs. Live view works and the relay VM is gone.

Lesson three: check the bouncer before the tunnel

A few days later the cameras went down. Tunnels were fine and OSPF was fine. The useful clue was the VyOS DNAT rule: its counters weren’t moving at all, so nothing was even reaching VyOS.

The culprit was CrowdSec on the hub UDM, with its UniFi bouncer, which had decided one of the CCTV app’s IPs was up to no good and banned it. The fix was deleting the decision with cscli decisions delete --ip, then putting every one of the app’s source IPs on a CrowdSec allowlist so it can’t happen again. The note I’ve left for future me: when an inbound forward stops working, look at CrowdSec first.

In the same family, UniFi’s IPS blocked my own SSH to VyOS at one point, and “suppress” didn’t lift it. Security tooling on the gateway is doing its job; it just doesn’t know what you meant.

A dashboard that doesn’t guess

Last bit: a live page showing every site, every tunnel and which path each site is actually using. The one rule was that it must never infer anything.

  • It runs as a small Python app (standard library only) in an unprivileged Alpine LXC on Proxmox, polling every 15 seconds.
  • Each VyOS is asked over its HTTP API for show ip route to a probe address (the other hub’s loopback, or the preferred hub’s for a spoke). The outgoing interface is the answer. If a router can’t be polled, its path shows Unknown, not a best guess.
  • Tunnel state comes from show ip ospf neighbor at both ends: Up, Half up, Down or Unknown.
  • The page is an adaptive grid of tiles: hubs across the top, one tile per spoke, fitting a 4K wallboard without scrolling and still usable on a phone. A big red banner appears if the data goes stale.

VyOS API keys have full admin rights, as there’s no read-only key. So each router’s API listens only on its loopback, accepts exactly one client address, and has its own key that lives in the password manager. One firewall policy on the hub UDM lets the dashboard reach the loopback range, and the other sites are reached through the tunnels.

Next up is the second spoke, then a lot more of them. With OSPF, adding one is now a PSK, a VTI, a peer and a few OSPF lines on each hub, and the routing sorts itself out.

$ systemd-analyze Startup finished in 6m 28s (reading, 1,424 words) $ echo $? 0

XP installed