Ubiquiti Networks

Resolving UniFi SD-WAN / Site Magic "Connecting" State & Spoke-to-Spoke Collisions

Overview

In multi-site UniFi Site Magic SD-WAN deployments across private or CGNAT WAN interfaces, branch gateways can become stuck in a "Connecting" state or experience spoke-to-spoke tunnel collisions. Migrating from a Full Mesh topology to a Single-Hub topology anchored on a public IPv4 headend restores deterministic WireGuard tunnel stability.

1. Problem Description

When deploying UniFi Site Magic SD-WAN across multiple branch sites containing UniFi Cloud Gateways (e.g., UCG-Ultra) and a central headend (e.g., UDM-Pro):

  1. One or more spoke sites remain permanently stuck in the "Connecting" state in UniFi Site Manager.
  2. A flapping/mutual-exclusion symptom occurs: When Spoke A connects, Spoke B disconnects or fails to connect, and vice versa.
  3. System event logs/SIEM alerts report high-severity configuration rollbacks on the gateways:
    CEF:0|Ubiquiti|UniFi Network|...|Gateway Config Change Failed|10|... msg=Gateway configuration changes could not be applied.

2. Root Cause Analysis

This behavior is typically driven by two interacting network conditions:

A. Full Mesh Failure Across Private / CGNAT WANs

  • The Mechanism: By default, standard Site Magic builds a Full Mesh topology where every site attempts direct peer-to-peer WireGuard tunnels with every other site via UDP hole punching (STUN).
  • The Failure: If multiple branch sites reside behind ISP Carrier-Grade NAT (CGNAT) or private upstream modems (WAN IPs in RFC 1918 space like 10.x.x.x or 192.168.x.x, or RFC 6598 space 100.64.0.0/10), direct spoke-to-spoke UDP negotiation fails. Neither gateway can accept inbound handshakes from the other.

B. Upstream Port / NAT State Collisions

  • When spoke sites with private WANs attempt to continuously negotiate tunnels against the central headend from behind strict/symmetric NAT or overlapping upstream states, the cloud broker and routing daemons hit race conditions.
  • When route table injection or WireGuard interface instantiation fails at the local gateway level, the internal management service (ubios-udapi-server) aborts the provisioning commit and rolls back to the prior configuration, leaving the dashboard stuck in "Connecting".

3. Diagnostic Procedures

1. Identify WAN Addressing Types

In UniFi Site Manager or UniFi Network > Settings > Internet, verify the WAN IPv4 address on all participating consoles:

  • Globally Routable Public IP (e.g., 64.x.x.x, 72.x.x.x): Capable of terminating inbound WireGuard peerings.
  • RFC 1918 / CGNAT IP (10.x.x.x, 172.16-31.x.x, 192.168.x.x, 100.64-127.x.x): Inbound tunnel termination will fail unless routed strictly outbound to a static public anchor.

2. Verify Commit Failures via Gateway CLI (SSH)

Connect via SSH to the gateway throwing errors and inspect recent daemon logs:

# Check the last failed commit in syslog
cat /var/log/messages | grep -i "commit failed" -B 5 -A 10

# Check ubios-udapi-server for route/interface compilation errors
journalctl -u ubios-udapi-server -e --no-pager

3. Inspect Active WireGuard Handshakes

wg show
  • No latest handshake or > 120s: WireGuard packets are dropped by upstream ISP/NAT.
  • transfer: 0 B received: Outbound packets sent, inbound responses blocked.

4. Resolution Steps

Step 1: Migrate Topology to Hub-and-Spoke

Transitioning away from a Full Mesh eliminates direct branch-to-branch hole-punch attempts between CGNAT-constrained devices.

  1. Navigate to UniFi Site Manager (unifi.ui.com) > SD-WAN / Site Magic.
  2. Remove any failing mesh groups.
  3. Select Create New SD-WAN Group and configure:
    • Hub Topology: Single
    • Hub: Designate the unit with a dedicated public IPv4 address (e.g., Main Office - UDM Pro).
    • Spokes: Select the branch gateways (e.g., Secondary Office - UCG Ultra, Overseas Office - UCG Ultra, etc.).

Step 2: Correct Tunnel Redundancy and Routing Parameters

  • VPN Tunnels: Set to Failover or Single (1 tunnel per spoke).
    • Do not select 4 (Highly Redundant) unless both the Hub and Spokes have dual active physical WAN connections configured with multi-path routing.
  • Hub Networks: Under Hub Networks and WANs, click Select and specify which corporate subnets on the Hub need to be accessible.
  • Enable Subnet Overlap with SNAT: Uncheck this option unless physical sites share identical IP subnets (e.g., both sites using 192.168.1.0/24). If subnets are unique, native layer-3 routing should be maintained.
  • Isolate Spokes: Check this option if branch offices only require access to central Hub resources and do not need to route directly to each other.

Step 3: Enforce Non-Overlapping Local Subnet Allocation

Ensure every site uses distinct, non-overlapping /24 subnets across all configured local networks and VLANs.

Reference Implementation Scheme

Site Role Device Subnets Assigned
Hub (HQ) UDM-Pro 192.168.10.0/24, 192.168.20.0/24, 192.168.30.0/24, 192.168.40.0/26
Spoke 1 UCG-Ultra 192.168.1.0/24, 192.168.2.0/24, 192.168.3.0/24
Spoke 2 UCG-Ultra 192.168.11.0/24, 192.168.22.0/24, 192.168.33.0/24
Spoke 3 (New) UCG-Ultra 192.168.100.0/24, 192.168.200.0/24

5. Verification

  1. In UniFi Site Manager, verify that the Hub and all Spokes display solid green status indicators.
  2. From a host on Spoke 2 or Spoke 3, run a ping and trace route to the Hub gateway:
    ping 192.168.1.1
    traceroute 192.168.1.1
  3. Run wg show on any Spoke gateway to confirm active handshakes update every 120 seconds or fewer, with balanced transfer: ... received / sent metrics.

6. Best Practices for Adding Future Branch Sites

  1. Pre-stage IP Plans: Before deploying a new gateway, assign LAN/VLAN subnets that do not conflict with the Hub, other Spokes, or common ISP modem defaults (192.168.0.0/24, 192.168.1.0/24).
  2. Upstream Modem Bridge Mode: Whenever possible, place ISP equipment in IP Passthrough or Bridge Mode to provide the branch gateway with an unrestricted public IP.
  3. Single Management Tenant: Verify all gateways remain adopted under the same Ubiquiti SSO Workspace/Owner account to ensure seamless key exchange.

Tags

UniFi Site Magic SD-WAN WireGuard CGNAT Troubleshooting