Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is port forwarding necessary?

I've been investigating networking for use in a two-player game I'm writing, and I'm still not clear on when a device must have a port forwarded in order to communicate with the outside world.

From what I've seen in other games, port forwarding is always required in order to host a server, but is not required on the client. In addition, there are other situations, such as skype (which, to my understanding is ultimately client to client), where neither end must forward a port.

So my question is, in over-the-Internet communication, when is and isn't port forwarding necessary, and what steps can i take as a developer to make it so my users don't have to worry about it? Thanks in advance!

like image 864
exists-forall Avatar asked Sep 05 '12 22:09

exists-forall


2 Answers

Port forwarding is needed when a machine on the Internet needs to initiate a connection to a machine that's behind a firewall or NAT router. If the connection is initiated by the machine behind the firewall, the firewall/router automatically recognizes the reply traffic and sends it to the machine that opened the connection.

But if a packet arrives on the external interface, and it's not a part of such a connection, the router needs to know what to do with it. By default, it will reject it. But if forwarding is configured for the port, that tells it what internal machine to send it to.

Put another way: you need port forwarding if you want to run a server behind the NAT firewall/router, you don't need it if you're just running a client.

like image 122
Barmar Avatar answered Oct 22 '22 20:10

Barmar


There is reason why Skype don't (not always) need manual setting of port forwarding:

When you install Skype, a port above 1024 is chosen at random as the port for incoming connections. You can configure Skype to use a different port for incoming connections if you wish, but if you do, you must open the alternative port manually.

If the port chosen for incoming connections becomes unavailable, by default ports 80 and 443 will be used as alternatives. If another application (such as Apache HTTP server or IIS) uses these ports, you can either configure the application to use other ports, or you can configure Skype to not use these ports.

Port forwarding is must if you host a server. You can use same technique as Skype... I am not sure if there is any other option...

like image 34
PrimosK Avatar answered Oct 22 '22 20:10

PrimosK