Reading — step 1 of 5
Read
NAT Traversal & Endpoints
Most home/mobile networks are behind NAT. The client's public IP is the router; internal IP is private.
WireGuard's NAT handling:
- Client initiates: outbound UDP packet creates NAT mapping. Server learns client's mapped public IP+port.
- Server replies to learned endpoint. Mapping persists for ~30s by default.
- PersistentKeepalive: client sends empty keepalive every 25s. Resets the NAT timeout.
- Symmetric NAT: maps differently per destination. Two peers behind symmetric NATs can't reach each other directly.
Without keepalive: NAT mapping expires when traffic idles. Server unable to send. Reconnection requires fresh client-initiated packet.
For peer-to-peer (no central server):
- STUN (RFC 5389): query an external server for your public IP+port.
- TURN (RFC 5766): relay traffic via a public server when direct fails.
- ICE (RFC 8445): try direct, then NAT-punching, then TURN.
WireGuard doesn't include these; it's point-to-multipoint with one peer always reachable.
Tailscale's MagicDNS + NAT punching:
- Each peer registers its public endpoint candidate(s) with a coordination server.
- Peers exchange candidates via the coord server.
- Try direct UDP to each candidate. If it works, use it.
- Fall back to DERP relays (Tailscale-operated) if direct fails.
UDP hole punching:
- Both peers send UDP packets to each other's likely public endpoint AT THE SAME TIME.
- The first packet creates a NAT mapping.
- The reply arrives through that mapping.
Symmetric NAT defeats hole punching. Most home routers are not symmetric (port-restricted cone NAT).
IPv6 helps: no NAT needed if both peers have IPv6.
Mobile/cellular networks often have CGNAT (carrier-grade NAT). Hole punching usually fails. Relays needed.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…