Port numbers in Linux

1. Port number in linux

In Linux, a port number is an abstract number used to identify a network application process. In network communications, the Transmission Control Protocol (TCP) or User Datagram Protocol (UDP) is used to pass data between computers. Each computer host can run multiple applications at the same time, and each application needs to use a unique port number to identify it and other applications it communicates with on the network.

In Linux, well-known port numbers are usually between 0 and 1023, which are used to identify widely used network services (such as SSH, HTTP, FTP, etc.), while private port numbers are usually between 1024 and 65535. These private port numbers are often allocated dynamically by specific applications or operating systems, and they are generally not used in a standardized way, such as for application development or temporary Internet connections.

You can use netstatthe command or sscommand to view the running process and the occupied port. For example, the following command will list currently running processes and their associated port information:

netstat -tuln    # 列出 TCP 和 UDP 协议的监听端口
ss -tuln         # 列出 TCP 和 UDP 协议的监听端口(更快但是没有 netstat 更传统)

Among them, -tmeans to list the running processes using the TCP protocol, -umeans to list the running processes using the UDP protocol, -lmeans to list the currently listening port number, -nmeans to display the port number in numeric form.

These commands can view all the port numbers on the computer. If you want to view a specific port number, you can add the port number at the end of the command. For example, the following command is a common way to find all SSHports :

netstat -tuln | grep ssh    # 搜索 SSH 端口
ss -tuln | grep ssh

These commands will list all processes using the SSH port, and the IP address and port number they are listening on.

2. The role of the port number

In Linux, a port number is an abstract number used to identify a network application process. It plays a vital role in network communication. Each computer host can run multiple applications at the same time, and each application needs to use a unique port number to identify it and other applications it communicates with on the network.

When an application is started, it needs to bind to a specific port number so other applications can find it on the network and communicate with it. For example, when a web server application starts, it creates a network socket listening on a specific port so that it can accept connection requests from clients. When a client sends a request, it specifies the destination port number to establish a connection with a specific process of the server. The process then parses the request and returns a response. The use of port numbers on the Internet allows applications to communicate between the same computer or across computers, and provides us with an easy and convenient way to perform online tasks such as sending emails, searching the web or storing data.

In summary, port numbers emerged to help communicate between various applications on the network and played a vital role.

3. Range of port numbers

In Linux, a port number is an abstract number used to identify a network application process, usually represented by a 16-bit integer. Common usage areas are as follows:

  • Well-known port numbers: range from 0 to 1023, used to identify widely used network services (such as SSH, HTTP, FTP, etc.).
  • Registered port numbers: range from 1024 to 49151, used to identify common network applications.
  • Dynamic or private port numbers: range from 49152 to 65535, generally assigned dynamically by specific applications or operating systems, and can also be used for development or temporary Internet connections.

It should be noted that this classification is not static, and the specific port number not only depends on the brand, version, and usage of the application, but may also vary due to factors such as the operating system or network environment.

In addition, in Linux, the scope, allocation, and management of port numbers are the responsibility of the Internet Assigned Numbers Authority (IANA). This organization maintains and manages all Internet standard numbers, including IP addresses, Domain Name System, and port numbers.

In short, the range of port numbers used in Linux is determined by multiple factors such as applications, operating systems, and network environments, and is managed and allocated by the IANA organization.

Guess you like

Origin blog.csdn.net/shouhu010/article/details/130933594