You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concepts/holepunching.mdx
+41-18Lines changed: 41 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,13 @@
2
2
title: "Holepunching"
3
3
---
4
4
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.
6
12
7
13
## The Problem: NAT Blocks Direct Connections
8
14
@@ -13,19 +19,37 @@ something you requested. The combination of NAT (which translates addresses) and
13
19
firewall rules (which filter traffic) makes direct connections
14
20
challenging.
15
21
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
+
16
27
Traditionally, this problem was solved by:
17
28
-**Port forwarding**: Manually configuring your router to allow specific connections (tedious and requires technical knowledge)
18
29
-**Relay servers**: Routing all traffic through a third-party server (slow and expensive)
19
30
31
+
20
32
## The Innovation: Holepunching
21
33
22
34
**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.
23
35
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
25
42
26
43
### 1. Initial Contact Through a Relay
27
44
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.
29
53
30
54
### 2. Sharing Connection Information
31
55
@@ -34,6 +58,18 @@ Through the relay, peers exchange their:
34
58
-**Port numbers** (the specific door number the router assigned them)
35
59
-**Local addresses** (in case they're on the same network)
36
60
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
+
37
73
### 3. Simultaneous Outbound Connection
38
74
39
75
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
44
80
45
81
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.
46
82
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
58
84
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:
Holepunching works in most network configurations, but some corporate firewalls or cellular networks may still require relay fallback. iroh handles this automatically.
0 commit comments