Understanding port forwarding and NAT

nat;tcp

I've got some confusion about port forwarding vs NAT. I know the problems NAT causes for P2P, and that there exist some solutions to it (STUN,TURN,etc) which require a relay server to setup direct connections between the peers.

Is port forwarding an alternative to STUN/TURN regarding the NAT problem? Can two peers behind NAT who have both port forwarded connect with TCP to each other directly?
For example I want to develop an app and I'd rather not have to have a server sitting 24/7 to relay connections, but instead having peers maybe do port forwarding and then they can speak to each other directly.

Best Answer

Two peers behind a NAT, using DNAT (or "port forwarding") aren't technically behind the NAT anymore.

When this scheme is used, connecting to the public IP makes the NAT box forward the packets to an internal system. So, to everyone involved, it looks just like the internal machine is actually not behind the NAT. So if at least one of the peers is using this scheme, STUN is no longer needed.

Of course, the fact that the NAT box mangles packets introduces lots of problems, but if you don't include IPs and ports in your messages you should be fine.

Another problem with this scheme is that you need the cooperation of the NAT box administrator, which isn't always easy to get.

Related Question