Behind NAT to behind NAT connection
Asked Answered
R

2

12

I've come across an interesting problem. Basically I have 2 mobile phones that are both behind NATs. I want to communicate directly between the 2 devices using UDP.

I know if I initiate a connection from the phones to a server then I can push data back down that connection to the phone (ie send it back from the same port that received the message to the same ip and port that it was received from). So I can easily communicate between the 2 devices by connecting both phones to the server. Then sending data to the server and having it re-routed back to the phones. This bypasses any NAT traversal issues I may come up against.

However I would rather just use the server to point the 2 devices at each other and then let them communicate directly. How would I go about doing this? Is it possible without using something like uPnP?

Any help would be much appreicated!

Edit: I found this document http://www.brynosaurus.com/pub/net/p2pnat/ It looks like hairpin translation is what I'm after but it doesn't look to be widely supported. I wonder how good mobile ISP's support for UPnP is?

Rattlebox answered 22/2, 2011 at 11:51 Comment(3)
Your question was "I wonder how good mobile ISP's support for UPnP is?". All questions do explain what Hole Punching is, but none of them answers the question about the current support. Oh what fun :-) Thank you for the link to the p2pnat paper.Honky
Did you found the solution for this in the recent years? I also have three distant networks (all with LTE modems, ISP NAT without uPNP) which I would like to connect together. Now I am using Pritunl OpenVPN, but I would like to have the mediator server only for being a mediator, as you described, not to route all traffic trough it.Sunk
Found ZeroTier which looks like exactly the tool for the job (could not edit the comment because >5 min).Sunk
O
4

What you're looking for is UDP hole punching, see e.g. http://en.wikipedia.org/wiki/UDP_hole_punching

The basic idea is simple, you tell each endpoint the ports to use, and they start sending udp packets. The NAT'ing devices will set up a traversal rule when they see the first outgoing packet, and then the next attempt from the other end will match this traversal rule.

Overwhelm answered 22/2, 2011 at 11:56 Comment(1)
Hole punching is all well and good if each router has external visibility which I can't be sure of :( This doc brynosaurus.com/pub/net/p2pnat has a good explanation of hole punching as well as "hairpin translation" which looks more what I'm after but, alas, is not well supported :(Rattlebox
B
4

You need a mediator server, so the clients can tell where they are. Then one opens a server by uPNP, and the other connects to it.

Bebe answered 22/2, 2011 at 11:55 Comment(2)
Yeah that would be ideal if I can use it. UPnP does not work on a multi NAT layer network topology though :(Rattlebox
multi-nat? On BOTH sides? Is this china?Bebe
O
4

What you're looking for is UDP hole punching, see e.g. http://en.wikipedia.org/wiki/UDP_hole_punching

The basic idea is simple, you tell each endpoint the ports to use, and they start sending udp packets. The NAT'ing devices will set up a traversal rule when they see the first outgoing packet, and then the next attempt from the other end will match this traversal rule.

Overwhelm answered 22/2, 2011 at 11:56 Comment(1)
Hole punching is all well and good if each router has external visibility which I can't be sure of :( This doc brynosaurus.com/pub/net/p2pnat has a good explanation of hole punching as well as "hairpin translation" which looks more what I'm after but, alas, is not well supported :(Rattlebox

© 2022 - 2024 — McMap. All rights reserved.