Bottom line: WireGuard has no built-in endpoint discovery, so a peer with a changing IP needs one fixed relay, or a dynamic DNS name updated by the peer, plus PersistentKeepalive to hold the tunnel open. Both sides behind CGNAT needs a relay; one side with a public IP is enough.

Pick a topology first

Situation Approach
One side has a static public IP point the other at it, DDNS not needed
One side has a dynamic public IP DDNS + short TTL + keepalive
Both behind CGNAT a cheap VPS relay with two peers
Behind CGNAT, one side only relay for that side

DDNS version

The dynamic side reports its address on every change:

1
2
3
4
#!/bin/sh
IP=$(curl -s --max-time 8 https://api.ipify.org)
curl -s -H "Authorization: Bearer $TOKEN" \
"https://api.dns.example/update?name=home.example.com&ip=$IP"

TTL 60 s. WireGuard resolves the Endpoint at handshake time, so a stale record costs one failed handshake, retried at the next PersistentKeepalive tick.

Keepalive

1
2
3
4
5
[Peer]
PublicKey = ...
Endpoint = home.example.com:51820
AllowedIPs = 192.168.50.0/24
PersistentKeepalive = 25

Without PersistentKeepalive the NAT mapping expires in 30–120 s and the peer becomes unreachable from the other side. 25 s is the usual value.

The relay version

A $3 VPS with two peers, AllowedIPs on each pointing at the other side’s LAN, and IP forwarding enabled:

1
2
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE

Both LANs route to each other through the relay. Traffic is decrypted at the relay — fine for a homelab, not for a compliance boundary.

Hardening

  • AllowedIPs per peer, never 0.0.0.0/0 on a peer that should only reach one subnet
  • Private keys in files with mode 600, never in the repo
  • A separate wg interface per peer group; one interface shares the routing table
  • MTU 1420 or lower if PPPoE is in the path — a black hole is the classic symptom of 1500

Verify

wg show handshake age, then ping and a curl to an internal service. A handshake under 180 s old with no traffic is a routing or MTU problem, not a crypto one.

Operating notes

WireGuard has no discovery. One fixed endpoint or a relay — decide from the topology before writing config.

1
2
3
static IP → point at it
dynamic IP → DDNS TTL 60 + PersistentKeepalive 25
CGNAT both sides → VPS relay, two peers, MASQUERADE

DDNS reporter

1
2
IP=$(curl -s --max-time 8 https://api.ipify.org)
curl -s -H "Authorization: Bearer $TOKEN" "https://api.dns.example/update?name=home&ip=$IP"

A stale record costs one failed handshake, retried at the next keepalive tick.

Relay caveat

Traffic is decrypted at the relay. Fine for a homelab, not for a compliance boundary.

Verify

wg show handshake age under 180 s, then ping an internal host. A fresh handshake with no traffic is routing or MTU — try 1420 before debugging crypto.

FAQ

Why does WireGuard need DDNS or a relay when a peer has a dynamic IP?

WireGuard has no built-in endpoint discovery, so a peer with a changing IP cannot be found unless something fixed points to it. Either one side has a static public IP to point at, or the dynamic side updates a DDNS name, or both sides use a relay. Decide this from your topology before writing any config.

What happens if I don’t set PersistentKeepalive?

Without PersistentKeepalive the NAT mapping expires in 30–120 s and the peer becomes unreachable from the other side. Setting it to 25 s is the usual value and holds the tunnel open. The keepalive tick is also when a stale DDNS record gets retried after one failed handshake.

How fast does a DDNS update take effect after my IP changes?

Use a TTL of 60 s. WireGuard resolves the Endpoint at handshake time, so a stale record costs one failed handshake, which is retried at the next PersistentKeepalive tick. With keepalive at 25 s, recovery is quick.

What if both sides are behind CGNAT?

You need a relay: a cheap VPS with two peers, AllowedIPs on each pointing at the other side’s LAN, and IP forwarding enabled with a MASQUERADE rule. Both LANs then route to each other through the relay. Traffic is decrypted at the relay, which is fine for a homelab but not for a compliance boundary.

A handshake succeeds but no traffic passes — what should I check?

Check wg show for a handshake age under 180 s, then ping and curl an internal service. A fresh handshake with no traffic points to a routing or MTU problem, not a crypto one. If PPPoE is in the path, try MTU 1420 or lower — a black hole is the classic symptom of 1500.