跳到主要内容
uencoder

STUN Protocol Reference

Reference 为 STUN (RFC 8489): NAT discovery, attributes, 和消息结构.

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
cookie + txn ID
attributes
TLV format
MAPPED-ADDRESS etc.
magic cookie
0x2112A442
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
mapping
classification
Deprecated in 5389
unreliable
keepalive
Maintain NAT mapping
periodic STUN

相关工具

参考链接