Skip to content

Commit 78da398

Browse files
committed
Improve the holepunching page based on feedback
1 parent 77b2a14 commit 78da398

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

concepts/holepunching.mdx

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
title: "Holepunching"
33
---
44

5-
When two devices want to connect directly over the internet, they face a common problem: **Network Address Translation (NAT)**. Most home and office networks use NAT, which acts like a one-way door—devices inside the network can reach out to the internet, but the internet can't easily reach back in.
5+
With holepunching, iroh applications can:
6+
- **Connect directly** between devices without manual network configuration
7+
- **Reduce latency** by avoiding servers when possible
8+
- **Save bandwidth** by keeping data transfer peer-to-peer
9+
- **Improve resilience and reliability** by not depending on all traffic being sent through third parties
10+
11+
The best part? All of this happens automatically—you don't need to understand the technical details to benefit from it.
612

713
## The Problem: NAT Blocks Direct Connections
814

@@ -13,19 +19,37 @@ something you requested. The combination of NAT (which translates addresses) and
1319
firewall rules (which filter traffic) makes direct connections
1420
challenging.
1521

22+
Most home and office networks use NAT, which acts like a one-way door—devices
23+
inside the network can reach out to the internet, but the internet can't easily
24+
reach back in. This causes reliance on central servers, which can introduce
25+
latency and reliability issues.
26+
1627
Traditionally, this problem was solved by:
1728
- **Port forwarding**: Manually configuring your router to allow specific connections (tedious and requires technical knowledge)
1829
- **Relay servers**: Routing all traffic through a third-party server (slow and expensive)
1930

31+
2032
## The Innovation: Holepunching
2133

2234
**Holepunching** is a clever technique that works around NAT and firewall restrictions to allow direct connections between peers without manual configuration or relying entirely on relay servers.
2335

24-
Here's how it works:
36+
iroh uses a sophisticated holepunching implementation built on top of QUIC and integrates with the relay system. The process relies on two key elements:
37+
38+
Holepunching works in most network configurations, but some corporate firewalls or cellular networks may still require relay fallback. iroh handles this automatically.
39+
40+
41+
## How Holepunching Works in iroh
2542

2643
### 1. Initial Contact Through a Relay
2744

28-
Both peers first connect to a shared [relay server](/concepts/relays). The relay acts as a meeting point where peers can coordinate without being able to connect directly yet.
45+
Both peers first connect to a shared [relay server](/concepts/relays). The relay
46+
acts as a meeting point where peers can coordinate without being able to connect
47+
directly yet.
48+
49+
The relay server observes each node's public IP address and port (the address
50+
from which it sees incoming traffic). This *reflective address* can be used by
51+
the remote peer to reach through the firewall, provided the firewall considers
52+
it expected traffic.
2953

3054
### 2. Sharing Connection Information
3155

@@ -34,6 +58,18 @@ Through the relay, peers exchange their:
3458
- **Port numbers** (the specific door number the router assigned them)
3559
- **Local addresses** (in case they're on the same network)
3660

61+
Nodes coordinate their holepunching attempts through the relay as a side
62+
channel. Both nodes simultaneously send UDP datagrams to each other's reflective
63+
addresses. Since both are sending on the same 4-tuple (source IP, source port,
64+
destination IP, destination port), the firewalls recognize the incoming packets
65+
as matching outbound traffic and allow them through.
66+
67+
Importantly, the relay server doesn't actively participate in holepunching -- it
68+
simply forwards encrypted packets between nodes without knowledge of whether
69+
they contain application data or coordination messages.
70+
71+
72+
3773
### 3. Simultaneous Outbound Connection
3874

3975
Here's the magic: both peers try to connect to each other **at the same time**. When peer A sends a packet to peer B's public address, A's NAT creates a mapping and the firewall creates a temporary rule allowing responses from B. When peer B sends a packet to peer A at the same moment, B's NAT and firewall do the same.
@@ -44,25 +80,12 @@ Because both NAT mappings are established and both firewalls now have rules expe
4480

4581
If holepunching fails (some networks use particularly strict NAT configurations), iroh automatically falls back to routing traffic through the relay server. This ensures connections always work, even if they can't be direct.
4682

47-
## Why This Matters
48-
49-
With holepunching, iroh applications can:
50-
- **Connect directly** between devices without manual network configuration
51-
- **Reduce latency** by avoiding relay servers when possible
52-
- **Save bandwidth** by keeping data transfer peer-to-peer
53-
- **Maintain privacy** by not routing all traffic through third parties
54-
55-
The best part? All of this happens automatically—you don't need to understand the technical details to benefit from it.
56-
57-
## How iroh Implements Holepunching
83+
## Read more
5884

59-
iroh uses a sophisticated holepunching implementation built on top of QUIC and integrates with the relay system. For technical details on the implementation, see:
85+
For technical details on the implementation, see:
6086

6187
- [iroh's holepunching implementation](https://docs.rs/iroh/latest/iroh/endpoint/index.html#nat-traversal)
6288
- [Relay system documentation](/concepts/relays)
6389
- [Dedicated infrastructure setup](/deployment/dedicated-infrastructure)
6490
- [Endpoint configuration](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html)
6591

66-
<Note>
67-
Holepunching works in most network configurations, but some corporate firewalls or cellular networks may still require relay fallback. iroh handles this automatically.
68-
</Note>

0 commit comments

Comments
 (0)