Session Traversal Utilities for NAT
lastmod 2024-11-06created 2019-02-1322 edits
Session Traversal Utilities for NAT (STUN) is a standardized set of methods, including a network protocol, for traversal of network address translator (NAT) gateways in applications of real-time voice, video, messaging, and other interactive communications.
STUN is a tool used by other protocols, such as Interactive Connectivity Establishment (ICE), the Session Initiation Protocol (SIP), or WebRTC. It provides a tool for hosts to discover the presence of a network address translator, and to discover the mapped, usually public, Internet Protocol (IP) address and port number that the NAT has allocated for the application's User Datagram Protocol (UDP) flows to remote hosts. The protocol requires assistance from a third-party network server (STUN server) located on the opposing (public) side of the NAT, usually the public Internet.
Originally, STUN was an acronym for Simple Traversal of User Datagram Protocol (UDP) through Network Address Translators, but this title was changed in a specification of an updated set of methods published as RFC 5389, retaining the same acronym.
About
- A STUN server sits on the public Internet. When a peer behind a router's NAT requests its public IP address, the server checks that address and tells the peer the IP:PORT information that is reachable from the external network.
- A peer on a NAT network has a private IP and so cannot communicate with WebRTC peers outside. It uses a STUN server to find out its public IP address and to find out whether anything in the router would get in the way of a direct P2P connection.
- A STUN server lets a client find its public address, the type of NAT it is behind, and the Internet-side port that the NAT associates with a particular local port. This information is used to set up UDP communication between the client and the VoIP provider, and thus to connect calls. The STUN protocol is defined in RFC3489.
- A STUN server listens on UDP port 3478, but the server hints to clients to run tests on an alternate IP and port number (a STUN server has 2 IP addresses). The RFC states that the ports and IPs are arbitrary.
Projects
Flow chart
Stun_flow_chart.png
NAT Behavior Discovery using STUN (RFC 5780)
As last time, be sure to read the blog posts below first to understand this content.
- How NAT devices should be built... (RFC 4787) - Part 1: Mapping Behavior
- How NAT devices should be built... (RFC 4787) - Part 2: Filtering Behavior
- Differences between STUN (RFC 3489) and STUN (RFC 5389/5780)
Troubleshooting
stun:localhost is not connect
When using Firefox, if connecting to stun:localhost with coturn or similar in Trickle ICE does not work properly, change the setting below on the about:config page and test again.
See Firefox#WebRTC Privacy for details.
If using Edge, see Edge#WebRTC LocalHost IP Setting. In short, see the Software\Policies\Microsoft\MicrosoftEdge\Main path in regedit.
If using Chrome, see Chrome:WebRTC#localhost ICE. In short, change the chrome://flags/#enable-webrtc-hide-local-ips-with-mdns flag to Disable.
| WARNING |
| Do not use a Loopback address such as |
See also
- WebRTC
- Session Traversal Utilities for NAT (STUN)
- Traversal Using Relays around NAT (TURN)
- Interactive Connectivity Establishment (ICE)
- Network address translation (NAT)
- UDP hole punching
Favorite site
- Wikipedia (en) STUN
- WebRTC in the real world: STUN, TURN and signaling
- Understanding STUN, TURN, and ICE
- WebRTC: Configure Your Own TURN/STUN Server (red5, TURN, STUN, WebRTC)
- [Recommended] TURN/STUN Server - Red5 Pro Server - Red5 Pro Docs
- (WebRTC) About STUN and TURN #1 - Overview
- [Figure] What is WebRTC? (Understanding STUN and TURN servers) (2)
Tutorials
- Introduction to NAT (Network Address Translation) (RFC 3022/2663)
- How NAT devices should be built... (RFC 4787) - Part 1: Mapping Behavior
- How NAT devices should be built... (RFC 4787) - Part 2: Filtering Behavior
- How NAT devices should be built... (RFC 4787) - Part 3: Deterministic Properties
- Differences between STUN (RFC 3489) and STUN (RFC 5389/5780) (STUN, NAT)
- NAT Behavior Discovery using STUN (RFC 5780) (STUN, NAT)