I just heard about this thing called "port forwarding". Now, as far as I learned, this means I can attach my IP adress to some port on the router. But why should I do it if the software on my computer automatically (of course through the code) can attach itself to some port on the router (i.e. "bind()" function).?

  • 3
    Software on your computer cannot bind to a port on any other device than the one of which it is executing.
    – Ron Maupin
    Feb 15 '17 at 14:51
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 16 '17 at 22:15

Port forwarding is not usually found in a true enterprise environment but may be used in a SOHO network when the router IP is the only public IP used. It enables incoming traffic to a certain port on the router to be forwarded to a defined IP and port (which is not necessarily the same port).

Software on your PC cannot bind to a port directly on the router, but even so it is possible to get a clash, therefore you must choose your ports accordingly.


Port forwarding is generally a technique that is used with network address translation and specifically DNAT.

Suppose there is an enterprise which has 2 servers 1 which accepting connections for SSH (port 22) and one is acting as web browser(port 80).

The enterprise is using a single public IP and further uses NAT for its 2 servers.

Now, one host that has never contacted this server tries to communicate with the web server.

Routing in the internet is always through public IP so using the enterprise IP the packet will reach the gateway router.

Now imagine the routing table for the gateway router. It has received packet which has a destination IP of its own interface. where does it send the packet now or rather how will it know it needs to send the packet to its web server which is defined behind the NAT.

For this we need port forwarding. This is basically saying whenever you get a packet with Dport 80 simply send it out of that interface.

Note that we were now unable to distinguish hosts based on IP addresses so now we are using ports to distinguish them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.