Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relation between port and IP address

Tags:

port

ip

My question is, if machine A have two IP address X,Y.

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

Say,is port unique by machine or by IP?

like image 321
httpinterpret Avatar asked May 30 '10 07:05

httpinterpret


People also ask

Is IP address and port address same?

The answer is no. The IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. The port number is used so the data is directed to the correct location within this device.

How many ports are in an IP?

Ports and Protocols. Between the protocols User Datagram Protocol (UDP) and Transmission Control Protocol (TCP), there are 65,535 ports available for communication between devices.

Does IP address include port?

An IP address can also include a port number. The port number follows the IP address and is separated by a colon (for example, 250.250. 250.1:8451).

Where is the port in an IP address?

The port number is “tacked on” to the end of the IP address, for example, “192.168. 1.67:80” shows both the IP address and port number. When data arrives at a device, the network software looks at the port number and sends it to the right program.


2 Answers

An IP address specifies a network interface (think an ethernet port on your computer or your WiFi connection). A port number specifies the process to which to route messages arriving on a given network interface. Hence you can use the same port number with different IP addresses, as they specify the port on which to listen on that given interface. Note, though, that you can even reuse a port number with the same IP address if you use the SO_REUSEADDR option when invoking the bind function.

like image 64
Michael Aaron Safyan Avatar answered Sep 20 '22 18:09

Michael Aaron Safyan


It's unique by IP. When you bind, (that's the important part), you bind to an IP and a port number, not a machine and a port number. To bind to all addreses you can use something like INADDR_ANY.

If you want to bind only to a few addresses, you have to do so "by hand". When the OS receives a packet it first checks he is the destination. Then it forwards it to the program that has requested (through bind, through connect etc) that he be the destination of packets with that specific IP and port number.

like image 31
nc3b Avatar answered Sep 21 '22 18:09

nc3b