Kelly Mears

NAT Traversal

NAT traversal is the set of tricks two devices behind separate routers use to open a direct connection anyway.

Networks & Distribution2 min read275 words9 out · 5 in
also calledHole PunchingSTUN/TURN

NAT traversal describes the techniques two devices behind network address translation use to establish a direct connection despite neither having a public, routable address of its own. Network address translation lets many devices on a private network share one public IP, which is why home internet works at all under IPv4 scarcity — but it also means an unsolicited inbound packet usually has nowhere to go, since the router has no mapping for it yet.

The classic fix is hole punching: both peers first send outbound packets to a public rendezvous server, which tells each peer the other's observed public IP and port. Each peer then sends a packet directly to the other's address. The outbound packet from each side creates a temporary mapping in its own NAT, and if timing lines up, the "unsolicited" inbound packet from the peer arrives just after that mapping opens and slips through. This is the mechanism behind most Peer-to-Peer connections and underlies WebRTC's ICE negotiation.

STUN servers tell a device what its own public IP and port look like from the outside — necessary because NAT rewrites both. TURN servers are the fallback when punching fails: a relay that both peers connect to normally, sacrificing the direct-connection latency win for guaranteed connectivity. ICE (Interactive Connectivity Establishment) is the algorithm that tries several candidate paths — host, STUN-reflexive, TURN-relayed — and picks the best one that actually works, coordinated through a Signaling Server that carries none of the media itself, only the negotiation.

Some NATs are more hostile than others: "symmetric" NATs assign a different external port per destination, which breaks the simplest hole-punching approach and often forces TURN.

See also9

WebRTC

The browser standard for direct peer connections carrying audio, video, and arbitrary data.

Networks & Distribution14 connections

Signaling Server

The small coordination service peers use to find each other before connecting directly.

Networks & Distribution10 connections

Peer-to-Peer

An architecture where participants communicate directly rather than through a central server.

Networks & Distribution13 connections

IPv6

IPv6 exists mainly to end address scarcity, with a large enough space that per-device NAT becomes optional.

Networks & Distribution15 connections

Anycast

Anycast announces the same IP address from many locations and lets normal routing send each client to the nearest one.

Networks & Distribution8 connections

Firewall

A filter that allows or blocks network traffic by rule, the oldest perimeter defense, and less sufficient on its own than it used to be.

Networks & Distribution22 connections

Network Address Translation

Rewriting the addresses in packets as they cross a router so that many devices can share one public IPv4 address, a stopgap that became permanent and broke the internet's end-to-end design.

Networks & Distribution17 connections

BitTorrent

A peer-to-peer file-sharing protocol from 2001 in which everyone downloading a file also uploads pieces of it to others, so popular files get faster as more people want them, and its legitimate and pirate uses.

Networks & Distribution5 connections

Videoconferencing

Real-time two-way audio and video between people in different places, promised for decades as the picturephone, made ordinary by broadband and webcams, and turned into daily infrastructure for work and school during the 2020 pandemic.

Networks & Distribution8 connections

Linked from5