Communication between port and IP address

My question is if machine A has two IP addresses X, Y.

Can it open port 80 twice, for example X:80 and Y:80 ?

Say, a unique port by machine or by IP?

+7
port ip
source share
3 answers

The IP address indicates the network interface (think about the network port on your computer or your WiFi connection). The port number indicates the process by which messages arriving at this network interface are sent. Therefore, you can use the same port number with different IP addresses, since they determine the port on which this interface will be listened. Note, however, that you can even reuse a port number with the same IP address if you use the SO_REUSEADDR parameter when calling the bind function.

+6
source share

It is unique by IP. When you bind (the important part), you bind to the IP address and port number, and not to the computer and port number. You can use something like INADDR_ANY to bind to all INADDR_ANY .

If you want to bind to only a few addresses, you must do this "manually." When the OS receives the packet, it first checks to see if it is the destination. Then he redirects it to a program that has requested (via bind, through connect, etc.) that it is the destination of packets with the specified IP number and port number.

+3
source share

port and IP have 1 to 1 mapping.

So yes, you could open port 80 on two different IP addresses on the same computer.

+1
source share

All Articles