Skip to content

Lesson 8 of 9 · 28m

NAT Traversal, Firewalls, Roaming, and the Failure Modes

How UDP state, NAT timeouts, endpoint changes, asymmetric firewalls, and carrier-grade NAT shape WireGuard behavior — and how to diagnose the failures operators actually see.

WireGuard's quiet design means it does not spend packets telling you why the network hates you. It retries handshakes in silence. The operator has to know the common failure modes: NAT state expires, firewalls admit one direction but not the other, endpoints change IP, or an ISP moves the client behind carrier-grade NAT.

UDP state expires

A typical home or enterprise NAT keeps UDP mappings for tens of seconds or a few minutes. If only one side initiates and then goes quiet, the mapping can disappear. The remote peer then cannot reach the NATed host until it sends outbound again.

That is the purpose of PersistentKeepalive:

[Peer]
Endpoint = 203.0.113.20:51820
PersistentKeepalive = 25

A 25-second keepalive is common because it is frequent enough for most NATs and cheap enough for mobile devices. It is not required on every peer. Put it on the side behind NAT or stateful filtering, usually the initiator.

Firewalls must allow endpoint traffic and payload traffic separately

The encrypted packets need UDP permission:

$ nft add rule inet filter input udp dport 51820 accept

Then forwarded payload traffic needs separate permission. Operators often open UDP/51820, see handshakes, and conclude the firewall is correct — while forwarded traffic is still dropped. Input and forward are different hooks:

$ nft add rule inet filter forward iifname "wg0" oifname "eth0" accept
$ nft add rule inet filter forward iifname "eth0" oifname "wg0" ct state established,related accept

That example is deliberately broad for illustration. Production should constrain sources and destinations.

Endpoint roaming is cryptographic continuity

WireGuard accepts authenticated packets from a changed source address and updates the peer endpoint. This is powerful for mobile devices: a laptop can move from Wi-Fi to cellular and continue after re-handshake. But it also means source IP is not your trust anchor. The key is.

If a server has no need to initiate to a roaming peer, the roaming peer may omit a static Endpoint; it initiates outward and the server learns its current address. Conversely, infrastructure peers normally need stable endpoints or DNS names.

DNS endpoints are only as fresh as resolution behavior

A config such as Endpoint = vpn-austin.example.net:51820 depends on client resolver behavior. Some implementations resolve once at startup; some re-resolve on retry. Do not assume DNS failover is instant. For HA designs, test the actual client behavior rather than relying on the TTL you wish were honored.

CGNAT breaks inbound expectations

Carrier-grade NAT means the user has no stable public address and often no way to accept inbound UDP consistently. Outbound initiation still works because NAT opens a mapping, but two CGNATed peers may not connect directly without hole punching or a relay. Vanilla WireGuard does not solve arbitrary NAT traversal by itself. This is one reason controller-based overlays use coordination, relays, and traversal techniques around the core protocol.

Diagnose in layers

Use this order:

$ wg show wg0
$ sudo tcpdump -ni eth0 udp port 51820
$ sudo tcpdump -ni wg0
$ ip route get DESTINATION
$ nft list ruleset | less

If UDP/51820 arrives on eth0 but handshake does not complete, suspect keys or local input filtering. If handshake completes but nothing appears on wg0, suspect payload routing or firewall forwarding. If traffic appears on wg0 but no reply returns, inspect the remote side — one-sided debugging lies.

Field notes

  • Keepalive is not a health check; it only maintains path state.
  • Endpoint changes are normal for mobile peers, alarming for fixed servers.
  • Stateful firewalls can permit outbound UDP yet drop long-lived return flows after state expiry.
  • Asymmetric routes may deliver encrypted packets correctly but send plaintext LAN replies elsewhere.
  • Packet capture both sides of the tunnel before concluding WireGuard is broken. Most accusations belong to the network around it.

Was this lesson helpful?

Sign in to rate