UDP hole punching
lastmod 2025-12-16created 2019-02-1915 edits
Hole Punching: the exact name is STUN (Simple Traversal of User Datagram Protocol Through Network Address Translators)
Because a home router also has routing characteristics, it needs to build a Routing Table; hole punching refers to exchanging packets with the other party in advance for the purpose of P2P communication, so that a Routing Table is written in each side's router.
UDP hole punching lets two clients form a direct P2P session through a rendezvous server, even when the clients are behind NAT.
About
You know how the punching tool that makes holes when you organize A4 paper files is called a hole punch? Literally, it means punching through the hole (port) blocked by NAT so that network packets can pass through.
NAT
- [Recommended] UDP - Hole Punching 2
There are the following four types.
- Full-cone NAT
- When a PC sends UDP data out of the router, the router remembers that PC's IP and port information and maps it to a router port.
- When data arrives at that router port, it is forwarded to that PC regardless of the source IP and port information.
- (Address)-restricted-cone NAT
- When a PC sends UDP data out of the router, the router remembers that PC's IP and port information and the destination IP, and maps them to a router port.
- When data arrives at that router port, the source IP information is compared, and if it matches the destination IP recorded in the router, it is forwarded to that PC.
- Port-restricted cone NAT
- When a PC sends UDP data out of the router, the router remembers that PC's IP and port information and the destination IP and Port, and maps them to a router port.
- When data arrives at that router port, the source IP information is compared, and if it matches the destination IP and Port recorded in the router, it is forwarded to that PC.
- Symmetric NAT
- When a PC sends UDP data out of the router, the router remembers that PC's IP and port information and the destination IP and Port, and maps them to a router port.
- If the destination IP or Port number changes, it maps to a new port.
- When data arrives at that router port, the source IP information is compared, and if it matches the destination IP and Port recorded in the router, it is forwarded to that PC.
See NAT for details.
Setting the MTU value
Apparently it may fail if the MTU value is larger than the interface's value ... <- Needs verification.
See also
Favorite site
- Wikipedia (en) Description of hole punching
- About hole punching technology
- [Recommended] Sukkarak's programming stories - Hole Punching 3
- Program Factory :: 3. What is Hole Punching