ArticleslgStudy

computer science

UDP hole punching

UDP hole punching is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand UDP hole punching rather than just read about it. In short: UDP hole punching is a commonly used technique employed in network address translation (NAT) applications for maintaining User Datagram Protocol (UDP) packet streams that traverse the NAT. NAT traversal techniques are typically required for client-to-client networking applications on the Internet involving hosts connected in private networks, especially in peer-to-peer, Direct Client-to-Client (DCC) and Voice over I…

UDP hole punching — main illustration
UDP hole punching — illustration

Key takeaways

  • UDP hole punching belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect UDP hole punching to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of UDP hole punching from memory before moving on to harder problems.

Reference excerpt

UDP hole punching is a commonly used technique employed in network address translation (NAT) applications for maintaining User Datagram Protocol (UDP) packet streams that traverse the NAT. NAT traversal techniques are typically required for client-to-client networking applications on the Internet involving hosts connected in private networks, especially in peer-to-peer, Direct Client-to-Client (DCC) and Voice over Internet Protocol (VoIP) deployments. UDP hole punching establishes connectivity between two hosts communicating across one or more network address translators. Typically, third-party hosts on the public transit network are used to establish UDP port states that may be used for direct communications between the communicating hosts. Once port state has been successfully established and the hosts are communicating, port state may be maintained either by normal communications traffic, or in the prolonged absence thereof, by keep-alive packets, usually consisting of empty UDP packets or packets with minimal, non-intrusive content.

Overview UDP hole punching is a method for establishing bidirectional UDP connections between Internet hosts in private networks using network address translators. The technique is not applicable in all scenarios or with all types of NATs, as NAT operating characteristics are not standardized. Hosts with network connectivity inside a private network connected via a NAT to the Internet typically use the Session Traversal Utilities for NAT (STUN) method or Interactive Connectivity Establishment (ICE) to determine the public address of the NAT that its communications peers require. In this process another host on the public network is used to establish port mapping and other UDP port state that is assumed to be valid for direct communication between the application hosts. Since UDP state usually expires after short periods of time in the range of tens of seconds to a few minutes, and the UDP port is closed in the process, UDP hole punching employs the transmission of periodic keep-alive packets, each renewing the life-time counters in the UDP state machine of the NAT. UDP hole punching will not work with symmetric NAT devices (also known as bi-directional NAT) which tend to be found in large corporate networks. In symmetric NAT, the NAT's mapping associated with the connection to the known STUN server is restricted to receiving data from the known server, and therefore the NAT mapping the known server sees is not useful information to the endpoint. In a somewhat more elaborate approach both hosts will start sending to each other, using multiple attempts. On a Restricted Cone NAT, the first packet from the other host will be blocked. After that the NAT device has a record of having sent a packet to the other machine, and will let any packets coming from this IP address and port number through. This technique is widely used in peer-to-peer software and Voice over Internet Protocol telephony. It can also be used to assist the establishment of virtual private networks operating over UDP. The same technique is sometimes extended to Transmission Control Protocol (TCP) connections, though with less success because TCP connection streams are controlled by the host OS, not the application, and sequence numbers are selected randomly; thus any NAT device that performs sequence-number checking will not consider the packets to be associated with an existing connection and drop them.

Flow Let A and B be the two hosts with internal IP addresses iAddrA and iAddrB respectively, each in its own private network; NA and NB are the two NAT devices with external IP addresses eAddrA and eAddrB respectively; S is a public server with a known IP address.

A and B each begin a UDP conversation with S; the NAT devices NA and NB create UDP translation states and assign temporary external port numbers ePortA and ePortB. S examines the UDP packets to get the source port used by NA and NB (the external NAT ports ePortA and ePortB). S informs B about the values of eAddrA:ePortA and informs A about the values of eAddrB:ePortB. A sends a packet to eAddrB:ePortB and B sends a packet to eAddrA:ePortA (not necessarily at the same time nor in any particular order). When those packets leave their private network, each NAT device adds an entry to its translation table: NA examines A's packet and finds an entry already exists (iAddrA, iPortA, eAddrA, ePortA) but the destination is different (S) . NA will create a new entry with the same translation for traffic sourced from A ( iAddrA) to B (eAddrB). NB examines B's packet and finds an entry already exists (iAddrB, iPortB, eAddrB, ePortB) but the destination is different (S). NB will create a new entry with the same translation for traffic sourced from B (iAddrB) to A (eAddrA). Depending on the state of each NAT's translation table upon arrival of the remote's packet: If the new entry was already added to NA's translation table before the arrival of B's packet, then NA passes B's packet, but otherwise drops it. If the new entry was already added to NB's translation table before the arrival of A's packet, then NB passes A's packet, but otherwise drops it. Once both NAT's have those tuples added, then "holes" have been "punched" in the NATs, allowing both hosts to directly communicate. If both hosts have Restricted cone NATs or Symmetric NATs, the external NAT ports will differ from those used with S. On some routers, the external ports are picked sequentially, making it possible to establish a conversation through guessing nearby ports.

See also Hamachi Hyphanet ICMP hole punching TCP hole punching Hole punching (networking) WebRTC Port Control Protocol (PCP) Teredo tunneling

References

External links Peer-to-Peer Communication Across Network Address Translators, PDF – contains a detailed explanation of the hole punching process STUNT – Simple Traversal of UDP Through NATs and TCP too Network Address Translation and Peer-to-Peer Applications (NATP2P)

Worked examples

Example 1 — a first encounter with UDP hole punching

Start with the simplest possible case. Write down what UDP hole punching claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to UDP hole punching before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about UDP hole punching ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of UDP hole punching

In research
UDP hole punching appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses UDP hole punching in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
UDP hole punching is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer network security, so understanding it makes those chapters shorter.
In everyday life
Look for UDP hole punching outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “UDP hole punching” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study UDP hole punching in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what UDP hole punching means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain UDP hole punching out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is UDP hole punching in simple terms?

UDP hole punching is a commonly used technique employed in network address translation (NAT) applications for maintaining User Datagram Protocol (UDP) packet streams that traverse the NAT. NAT traversal techniques are typically required for client-to-client networking applications on the Internet i…

Why does UDP hole punching matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study UDP hole punching?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on UDP hole punching.

Tags

  • Computer network security

Keep exploring