Skip to main content
Yukari

How NAT hole punching works

It is here for readers who are curious about how two devices behind home routers manage to talk directly to each other without port forwarding.

Why two home devices cannot just call each other

Most home and mobile connections sit behind NAT (Network Address Translation). Your router holds one public IP address from your ISP and shares it among every phone, laptop, and TV inside your home, each with a private address like 192.168.1.x.

When your laptop sends a packet out to a website, the router remembers the outgoing connection and lets the reply back in. When an unsolicited packet arrives from the outside, the router drops it because it has no idea which device inside your home should receive it.

Step 1: Detecting NAT type with STUN

Before trying to punch a direct tunnel, Yukari queries STUN servers (configured automatically, or customized under Advanced > STUN Servers). A STUN server simply echoes back the public IP and port it saw your packets come from.

By comparing the mapped ports across multiple STUN queries, Yukari classifies your NAT type and shows it on the Home screen:

NAT typeMapping behaviorDirect connection difficulty
Open Internet / Full ConeSame external port reused; any outside host can send to it once openedEasy
Restricted Cone / Port Restricted ConeSame external port reused, but router only accepts replies from IPs (or IP
port
pairs) you already sent packets to
Moderate (standard hole punching works)
Symmetric NATRouter assigns a different external port for every destination IP
port
Hard (requires port prediction or relay fallback)

Direct connection odds by NAT combination

Peer APeer BTypical result
Open Internet / Full ConeAny NAT typeDirect P2P
Restricted / Port Restricted ConeRestricted / Port Restricted ConeDirect P2P
Restricted / Port Restricted ConeSymmetric NATOften direct (via symmetric hole punching); falls back to relay if ports are unpredictable
Symmetric NATSymmetric NATUsually relayed; direct only if at least one router allocates ports predictably

Step 2: Coordinated hole punching (UDP and TCP)

When Peer A and Peer B want a direct connection:

  1. Both peers are already connected to a common Initial Peer (or another peer in the mesh), which acts as the signaling channel.
  2. Each peer asks STUN for its current public IP and port, then sends that candidate address to the other peer over the signaling channel.
  3. Both peers send packets toward each other's public IP and port at nearly the same time.
  4. Peer A's outgoing packet opens a temporary entry ("hole") in Router A's NAT table expecting replies from Peer B. Peer B's outgoing packet does the same on Router B.
  5. Once both routers have matching entries, packets pass straight between Peer A and Peer B without touching the relay server.

EasyTier supports both UDP and TCP hole punching, and also attempts UPnP / NAT-PMP port mapping if your router allows it (all individually toggleable under Advanced > P2P & NAT Traversal).

Dealing with symmetric NAT

With symmetric NAT, the port STUN sees is not the port the router will pick when talking to Peer B. EasyTier can attempt symmetric NAT hole punching by predicting nearby ports (or using birthday-paradox probing when the other side is a cone NAT).

When both sides are behind strict symmetric NATs or carrier-grade NAT (CGNAT) with random port allocation, direct hole punching may fail.

Automatic relay fallback

If a direct connection cannot be established, traffic does not drop. EasyTier routes encrypted packets through an intermediate node (a shared node or another reachable peer in your mesh) and continues trying to upgrade to a direct path in the background when conditions allow.

P2P tuning options

Most networks work fine with the default settings. If you have a specific constraint, Advanced > P2P & NAT Traversal exposes a few overrides:

  • Lazy P2P: Wait to punch a direct tunnel to a peer until you actually send traffic to it. Helpful in large networks to reduce idle keepalive traffic and battery use.
  • Need P2P: Ask other peers to connect directly to this node even if they have Lazy P2P turned on (useful for a game host or file server).
  • P2P Only: Never fall back to a relay; only talk to peers with a direct connection. Useful when you want strict zero-relay traffic and are fine with unreachable peers dropping out.
  • Disable P2P: Always relay traffic through other nodes instead of punching direct tunnels (peers that have Need P2P enabled can still initiate direct links).

Last updated: 12/2/26, 1:53 PM

Yukari

A cross-platform decentralized networking app built on EasyTier