P2P and NAT: How To Traverse NAT Davide Carboni © 2005-2006
P2P and NAT: How To Traverse NAT Davide Carboni © 2005-2006
P2P and NAT: How To Traverse NAT Davide Carboni © 2005-2006
Rules
Firewall
(Global IP addresses)
router
Rules
NAT
the process of network address
translation (NAT, also known as network
masquerading or IP-masquerading) involves
re-writing the source and/or destination
addresses of IP packets as they pass
through a router or firewall.
Why NAT is so popular
(Public IP addresses)
(Private IP addresses)
Main NAT
Internet
(Public IP addresses)
Multiple NAT
156.148.70.32
Main
Internet
ISP
(Public IP addresses) NAT
ISP 192.168.2.12
network
192.168.2.99
Home
NAT
(Private IP addresses)
Home
network
10.0.0.12
NAT Mappings
(1.1.1.4)
(192.168.2.2) (1.1.1.5)
A datagram
datagram S=1.1.1.5:10100
D=1.1.1.4:7777
S=192.168.2.2:4445
D=1.1.1.4:7777
Traversing a NAT that
does not collaborate
Relaying
Main
Internet 1
Relay S 2
NAT
NAT
Local
network
Local
network 10.0.0.12
192.168.2.99
host B
host A
Connection reversal
Main
Internet 2
rendezvous S
1
NAT 1.1.1.4
3
Local host B
network
192.168.2.99
host A
TURN protocol
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10100,
D=1.1.1.5:7777) D=1.1.1.5:7777)
Packet(S=1.1.1.5:4321, Packet(S=1.1.1.5:4321,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Packet(S=1.1.1.6:1234, Packet(S=1.1.1.6:1234,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Full cone mapping and policy
Mapping
192.168.2.2:4445 <-> 1.1.1.4:10100
Policy
ALLOW ALL TO 1.1.1.4:10100
Holes in Full Cone
rendezvous
1 NAT
5 3
host A
4
host B
Restricted cone
(192.168.2.2) (192.168.2.1) (1.1.1.4) (1.1.1.5) (1.1.1.6)
Restricted
Host A Host B Host C
cone
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10100,
D=1.1.1.5:7777) D=1.1.1.5:7777)
Packet(S=1.1.1.5:4321, Packet(S=1.1.1.5:4321,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Packet(S=1.1.1.6:1234,
D=1.1.1.4:10100)
X
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10100,
D=1.1.1.6:7777) D=1.1.1.6:7777)
Packet(S=1.1.1.6:4321, Packet(S=1.1.1.6:4321,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Restricted cone
mapping and policy
Mapping
192.168.2.2:4445 <-> 1.1.1.4:10100
Policy
ALLOW 1.1.1.5 TO 1.1.1.4:10100
ALLOW 1.1.1.6 TO 1.1.1.4:10100
Holes in Restricted Cone
rendezvous
NAT
1
5 3 4
host A
6
host B
Port restricted cone
(192.168.2.2) (192.168.2.1) (1.1.1.4) (1.1.1.5) (1.1.1.6)
Port - restr
Host A Host B Host C
cone
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10100,
D=1.1.1.5:7777) D=1.1.1.5:7777)
Packet(S=1.1.1.5:4321,
D=1.1.1.4:10100)
Packet(S=1.1.1.5:7777, Packet(S=1.1.1.5:7777,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Port restricted cone
mapping and policy
Mapping
192.168.2.2:4445 <-> 1.1.1.4:10100
Policy
ALLOW 1.1.1.5:7777 TO 1.1.1.4:10100
ALLOW 1.1.1.6:7777 TO 1.1.1.4:10100
Holes in Port restricted Cone
rendezvous
NAT
1
5 3 4
host A
6
host B
Symmetric NAT
(192.168.2.2) (192.168.2.1) (1.1.1.4) (1.1.1.5) (1.1.1.6)
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10100,
D=1.1.1.5:7777) D=1.1.1.5:7777)
Packet(S=1.1.1.5:7777, Packet(S=1.1.1.5:7777,
D=192.168.2.2:4445) D=1.1.1.4:10100)
Packet(S=192.168.2.2:4445, Packet(S=1.1.1.4:10179,
D=1.1.1.6:7777) D=1.1.1.6:7777)
Packet(S=1.1.1.6:7777, Packet(S=1.1.1.6:7777,
D=192.168.2.2:4445) D=1.1.1.4:10179)
Packet(S=1.1.1.6:7777,
D=1.1.1.4:10100)
X
Symmetric
mapping and policy
Mapping
192.168.2.2:4445 <-> 1.1.1.4:10100
192.168.2.2:4445 <-> 1.1.1.4:10179
Policy
ALLOW 1.1.1.5:7777 TO 1.1.1.4:10100
ALLOW 1.1.1.6:7777 TO 1.1.1.4:10179
Holes in Symmetric
STUN protocol
1.1.1.5
1.1.1.4
NAT
NAT Local
network
Local
network 10.0.0.12
192.168.2.99
host B
host A
TCP Hole punching
1.1.1.6
Main
rendezvous S Internet
NAT
NAT Local
network
Local
1.1.1.5:4444
network
host B
1.1.1.4:1234
host A
STUNT
1. CONNECT
NAT
host A
SOCKS BIND
server S
3. connect(33102) Socks proxy
2. Ok. Port=33102
1. BIND (localport=4445, S)
NAT
SocketAddress addr =
new InetSocketAddress("socks.mydomain.com", 1080);