Linux command to view ports: 1. lsof command, syntax "lsof -i:port number", can check port occupancy; 2. "netstat -tunlp" command, can display tcp, udp ports and Process and other related situations, the syntax is "netstat -nltp | grep port number".
The operating environment of this tutorial: linux7.3 system, DELL G3 computer.
Linux command to view ports:
The first: lsof command
lsof(list open files) is a Lists the tools used to open files on the current system.
lsof can check the port occupancy
lsof -i:端口号
Example: Check the occupancy of the server 8000 port:
Second :netstat -tunlp command
netstat -tunlp
is used to display tcp, udp ports and processes and other related conditions.
netstat -nltp | grep 端口号
-t (tcp) Show only tcp related options
-u (udp) Show only udp related options
-n Refuse to display aliases and convert all numbers that can be displayed into numbers
-l Only list the service status in Listen(listening)
-p Display the name of the program that establishes the relevant link
For example, to view the situation of port 8000, use the following command:
Several states of TCP connection
ESTABLISHED Established
CLOSED Closed
LISTENING Listening
FIN-WAIT-2 Wait for the connection to be closed
TIME-WAIT Wait for enough time to ensure that the server closes the connection normally
Related learning recommendations: linux video tutorial
The above is the detailed content of What is the command to view ports in Linux?. For more information, please follow other related articles on the PHP Chinese website!