STUN Protocol Referencia
Referencia para STUN (RFC 8489): NAT discovery, attributes, y mensaje estructura.
Message Structure
STUN messages have a 20-byte header containing magic cookie, transaction ID, and message length. Attributes follow as TLV (Type-Length-Value) structures. Key attributes include MAPPED-ADDRESS, XOR-MAPPED-ADDRESS, RESPONSE-PORT, and CHANGED-ADDRESS. The magic cookie 0x2112A442 identifies STUN packets and aids demultiplexing. Messages are sent over UDP; retransmissions handle reliability. The protocol is simple and stateless from the server perspective.
- header
- 20 bytes
- attributes
- TLV format
- magic cookie
- 0x2112A442
cookie + txn ID MAPPED-ADDRESS etc. identification Usage and Limitations
STUN reveals the public IP and port mapping as seen by the server. Classic STUN (RFC 3489) classifies NAT type but fails for symmetric NAT. RFC 5389/8489 deprecate classification, focusing on discovery. STUN is used by WebRTC, SIP, and ICE for connectivity establishment. The STUN server must be on the public internet. STUN cannot traverse all NAT types; TURN relay is needed for symmetric NAT. STUN also serves as a keepalive mechanism.
- discovery
- Public IP + port
- classification
- Deprecated in 5389
- keepalive
- Maintain NAT mapping
mapping unreliable periodic STUN