Can anyone explain how UDP hole punching works in a simple way? I know how NAT and PAT works, but can't get a clear idea about UDP hole punching.

  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Apr 1 '18 at 20:03

Details vary but basically it goes something like.

  • The two peers both open a UDP socket bound to a random local port
  • The two peers both contact a server on the internet. This server responds and tells them what IP and port their packet was received from. Since the server is on the Internet the IP/port seen by the server is the external IP and port
  • The two peers exchange information about the external IPs and ports through some mechanism.
  • The two peers start trying to send UDP traffic to each other.
  • Hopefully the external IP and port used by the NAT for the traffic to the server are the same as the external IP and port used for the traffic sent towards the other peer. So once both peers have sent packets out through their NATs the incoming packets match the mappings and peer to peer communication is established.

This strategy will work reliablly with full cone, restricted cone or restricted port cone NATs. It will work most of the time with port-preservative symmetric NATs. It will not work with randomising symmetric NATs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.