How Network Address Translator (NAT) works — screenshot of tailscale.com

How Network Address Translator (NAT) works

This Tailscale blogpost is an excellent long-form explanation of the fundamental techniques for NAT traversal, including how to overcome stateful firewalls and carrier-grade NATs for robust peer-to-peer UDP connections.

Visit tailscale.com →

Questions & Answers

What is NAT traversal?
NAT traversal refers to a set of techniques used to establish peer-to-peer connections between devices located behind Network Address Translators (NATs) or stateful firewalls. These methods allow direct communication even when traditional networking would prevent it.
Who would benefit from understanding NAT traversal?
Developers and network engineers building peer-to-peer applications, VPNs, or communication systems like VoIP, WebRTC, and online gaming would benefit. It's crucial for enabling direct connectivity across various network environments.
Why is NAT traversal necessary for peer-to-peer communication?
NAT traversal is essential because stateful firewalls and NAT devices typically block unsolicited inbound connections, making it impossible for two peers behind different NATs to initiate a connection directly. It overcomes these obstacles without requiring manual firewall configuration.
In what scenarios is NAT traversal particularly useful?
NAT traversal is particularly useful when building decentralized systems that require direct communication between endpoints, such as mesh VPNs like Tailscale, real-time communication protocols (WebRTC), or applications that need to bypass centralized relay servers for performance.
What is a key technical prerequisite for implementing NAT traversal?
A key technical prerequisite is building the protocol on UDP, as TCP adds significant complexity to NAT traversal. Additionally, direct control over the network socket is required to send and receive extra packets essential for the traversal process, distinct from the main protocol's data.