TCP/UDP hole punching from and to the same NAT network

loopbacknat;networkingtcpudp

I was wondering if tcp/udp hole punching would still work when you are in the same network (behind a NAT), and what the packet's path would be.

What happens when using hole punching on the same network, is that it will send a packet out with the same destination and source address. Only the source and destination port would differ. I imagine a router with NAT loopback enabled will handle this as it should, but how about other routers? Would they drop the packet, or would a router (the first?) from the ISP bounce the packet back after which it gets handled okay?

I'm wondering because I was thinking about using this technique to circumvent a block between peers in a network (like a school network where clients can only access the internet, but any contact with each other is blocked). The only other option is to use a man in the middle as proxy (tunnel?). The disadvantage of this is that you have to have a server with significantly more bandwidth than one that would only do hole punching. Also the latency would increase significantly.

Best Answer

That's called NAT Hairpinning. A NAT that support Hairpinning can do translation even if both peers are in the same NAT.

Related Question