-2

I read the answer in that link:

What is port forwarding and what is it used for?

And I asked myself - If "port-forwarding" is passing a specific package to a specific computer by a specific port, then why the same thing cant be achieved by binding the software to the port?

For example. Why does the next code in python:

 soc = socket.socket()
 soc.bind(('0.0.0.0', 80))
 soc.listen(1)
 client_soc, address = soc.accept()

Wouldn't be the same as doing port forwarding to port 80 to my computer on the LAN?

2 Answers2

2

Binding a process to a port is something that happens inside a host so that the process will receive data sent to the host on that port.

Port forwarding has to do with an intermediate node in the path to get to the host. If packets have their addresses changed by by the intermediate node because of NAPT, then a host outside the intermediate node cannot directly send packets to the host on the other side of the node performing NAPT. The intermediate node must know that any traffic destined to its address with a certain port must be sent to the destination host. That is port forwarding, which is really just a way to make a permanent entry in the NAT table.

Ron Maupin
  • 3,463
0

Wouldnt be the same as doing port forwording to port 80 to my computer on the LAN

It absolutely is not the same thing.

The code you supplied binds the port on the local machine. This action is independent of forwarding all traffic on a port to a specific client. You can bind a port on every client on your network but you can only forward the traffic on that port to a single client on the network.

Binding a port happens on the client side, but when you forward a port to a specific client, you are not necessarily binding that port on the client. The client still must have an application or service installed and configured to do that.

Ramhound
  • 44,080