Current location - Quotes Website - Collection of slogans - What is a port? What exactly does it do?
What is a port? What exactly does it do?
In the world of network, there are two very important concepts, one is IP address and the other is port. According to the IP address, you can find the terminals that communicate with each other, and according to the port, you can find the applications that communicate with each other, that is, different port numbers correspond to different applications.

The role of ports

An IP address identifies a host, and a host can provide a variety of services, such as web services, ftp services, remote desktops, and so on. How to distinguish different services? It is not enough to display only by IP address. Ip address and service have a one-to-many relationship, so port numbers are needed to distinguish them.

For example, when we visit today's headline website, the browser uses a random port greater than 1024, obtains the IP address of today's headline website through DNS, and accesses port 80 of the web service. The following figure shows the format of TCP message, in which the first two fields are source port number and destination port number.

Port classification

The port number is an integer ranging from 0 to 65535 (2 16- 1), which is divided into well-known ports and dynamic ports.

1) well-known ports, well-known ports are well-known ports, and some of them are established by convention. The range is from 0 to 1023, for example, the common www is 80, ftp is 2 1, telnet is 23, dns is 53, and so on.

2) Dynamic ports, which are generally not used for fixed allocation to a certain service, range from 1024 to 65535, and are dynamically allocated. When a process or application of the system needs communication, the host allocates an available port number for its use, and releases the occupied port number when the program is closed.

To sum up, IP address is used to uniquely identify a host, port number is used to uniquely identify different applications or processes, and quadruple (source IP address, source port number, destination IP address and destination port number) is used for a communication process.