Insights

NAT traversal: how devices connect across private networks

Learn how NAT traversal uses STUN, TURN and ICE, why direct connections can fail, and what connection details do and don't prove.

Illustration of cutaway three-way diverter valve.
On this page

NAT traversal is a set of methods for establishing and keeping connections across routers that use network address translation (NAT). It helps devices on separate private networks communicate. Some methods create a direct path, while others send traffic through a relay when a direct path isn't available.

In short:

  • Address discovery. Finding a public-facing address doesn't prove another device can reach it.
  • Direct connections. Devices can exchange traffic directly when a usable peer path exists.
  • Relayed connections. An intermediary carries the traffic when the application uses a relay.

Why two devices can't always connect directly

Hypothetical example: You and a friend want to share a file between devices on different home networks. Each device has a private Internet Protocol (IP) address used inside its own network. A public-facing address is what an outside server sees. A port identifies a communication endpoint at an address.

Your NAT router translates packet addresses and ports, creating a temporary mapping between private and public-facing endpoints. That mapping helps the router send matching return traffic to the right device. For Internet Protocol version 4 (IPv4), incoming packets usually need to be associated with an outbound connection.

Your browser's outbound request can create this mapping before the reply arrives. Your friend's device can't assume that sending traffic to your router's public address will reach your device. Traversal helps the devices find a usable route, but the result varies with the router's mapping behavior.

How the main traversal methods work

Session Traversal Utilities for NAT (STUN) discovers the address and port seen by a server. Traversal Using Relays around NAT (TURN) carries traffic through a relay server. Interactive Connectivity Establishment (ICE) gathers and checks possible connection paths, called candidates.

Hole punching here uses User Datagram Protocol (UDP), which sends packets without first establishing a transport connection. Universal Plug and Play (UPnP) lets a device request a port mapping from a compatible local router.

These methods differ in what they set up and whether a server carries your traffic.

Traversal methodMain jobTraffic pathMain limit
STUNDiscover server-seen address and portServer used for discoveryDoesn't prove peer reachability
UDP hole punchingUse outbound peer traffic to create mappingsDirect when usableDepends on mapping behavior
TURNRelay traffic between devicesThrough relay serverRelay must be reachable and allowed
ICEGather and check candidate pathsDirect or relayedDoesn't guarantee a direct path
Port forwardingConfigure an inbound mappingThrough configured routerDoesn't configure upstream NATs
UPnPRequest a local router mappingThrough compatible local routerLimited to local router scope

A server used for discovery or setup isn't necessarily in your file's data path. A TURN relay is in that path because it carries the traffic. ICE checks candidate paths, so don't treat it as a guaranteed “STUN first, TURN second” sequence. If your connection crosses several NAT routers, a local port request doesn't control the others.

Why a direct connection can still fail

Direct traversal can fail when a router uses different mappings for different destinations. The older label “symmetric NAT” describes this problem: the mapping found through a STUN server may differ from the one used for your peer. Devices behind the same NAT may also need hairpin support, which routes traffic sent to the public-facing address back inside the network. Without that support, exchanging public-facing addresses may not let those devices connect.

Use the connection details your application shows to separate address discovery from a working traffic path.

Your observationSupported meaningNot proven
A successful STUN responseAddress and port seen by that serverReachability from your peer
A working direct connectionDirect peer traffic works for this sessionSuccess on other networks or later sessions
A working relay connectionTraffic works through an intermediaryDirect peer connectivity
A connection fails after inactivityThe idle session stopped workingMapping expiry or a specific fault

A NAT binding is the stored address-and-port mapping, and it can expire after inactivity. Applications may send periodic outbound keep-alive packets to keep it active. If an idle session fails, check the app's connection status and keep-alive behavior before blaming the router. Mapping expiry is one possibility to investigate, not a diagnosis.

NAT behavior and firewall policy are separate concerns. A relay can provide another path when it's reachable and allowed, but NAT traversal itself doesn't grant permission or encrypt traffic. Check the app's current direct or relay status before naming the path. If it only shows a discovered address, the traffic path remains unconfirmed.

What NAT-T means in IPsec

In Internet Protocol Security (IPsec), NAT-T is a specific form of NAT traversal. It wraps Encapsulating Security Payload (ESP) traffic in UDP so NAT can work with the outer address and port.

The router example describes the ports this way:

In other words, RTR-Site1 encapsulates ESP packets inside UDP/4500 for Source and Destination Ports.

That port belongs to this IPsec context, not every NAT traversal method. It isn't a universal instruction to open a firewall port.

Where doxx.net fits. doxx.net offers direct device-to-device connections and full, unmodified file transfer between devices. If that matches your needs, create an account, download the app and connect a device or agent.

Ask an AI assistant

Share this article

Private Everywhere

Stop giving the internet everything

Keep your browsing, messages, files, and agents private.