## The operating environment of this article: linux6.4.3 system, Dell G3 computer. Linux system provides a variety of methods to query ports. The following are commonly used methods:How to query the port on Linux: 1. Use the netstat command, the command is "netstat -tuln"; 2. Use the lsof command, the command is "lsof -i"; 3. Use the ss command, the command is "ss -tuln"; 4. Use the nmap command, the command is "nmap -p
"; 5. Use the /proc file system by accessing /proc/net/tcp and /proc/net/ udp file.
Use the netstat command:
The netstat command can Used to display network connections, routing tables, network interfaces and other related information, including port information. All port information can be queried through the following command:netstat -tuln
Use the lsof command:
The lsof command can list the files currently opened in the system and can also be used to query port information. You can query all ports in use through the following command:lsof -i
Use the ss command:
The ss command is an alternative tool to netstat and can be used to query information such as network connections, sockets, and routing tables. All port information can be queried through the following command:ss -tuln
Use the nmap command:
nmap is a network detection and security scanning tool that can also be used to query port information. You can query the port information of the specified IP address through the following command:nmap -p <port> <ip>
Using the /proc file system:
The /proc file system of the Linux system provides an interface for accessing kernel and process information, and can also be used to query port information. By accessing the /proc/net/tcp and /proc/net/udp files, you can query the detailed information of the currently listening TCP and UDP ports. Summary: The above are several common methods. You can choose the appropriate method to query port information according to actual needs. In actual use, netstat and lsof are the most commonly used commands, and they provide more comprehensive and intuitive port information. The ss and nmap commands provide more powerful and flexible functions and are suitable for more complex network environments and requirements. At the same time, some port information can also be obtained by accessing the /proc file system, but the file content needs to be parsed and processed.The above is the detailed content of How to query the port in linux. For more information, please follow other related articles on the PHP Chinese website!