How to check the port occupation in Linux: Use [lsof -i port number or netstat -tunlp|grep port number]. Both commands can check what process the port is occupied by.
The operating environment of this tutorial: linux7.3 system, DELL G3 computer.
How to check port occupancy in Linux:
1. Commonly used commands:
(1) lsof -i port number
(2) netstat -tunlp|grep port number
Both commands can check what process the port is occupied.
2. lsof -i is used to display the conditions of processes that meet the conditions. lsof (list open files) is a tool that lists open files in the current system. Execute the lsof -i command as the root user, as shown below
The meaning of each column output by lsof is:
COMMAND: The name of the process or the method of starting the process
PID: process id
USER: process owner
FD: file descriptor
TYPE: Protocol type
DEVICE: Port number
SIZE/OFF: Offset
NODE: protocol name
NAME: node name
3. lsof -i: Port number, used to check the occupancy of a certain port, for example, to check the usage of port 22, lsof -i:22, as shown below
4. netstat -tunlp is used to display tcp, udp ports and processes and other related conditions. As shown in the figure below
, t, u, n, l, p in the command have different meanings:
-t Only displays those related to tcp
-u Only displays those related to udp
-n No time limit alias, can display all numbers converted into numbers
-l Only displays those in the Listen state
-p Displays the program names that establish these connections
5, netstat -tunlp|grep port number, used to check the process status of the specified port number, such as checking the status of port 22, netstat -tunlp|grep 22, as shown below
related Learning recommendation: linux video tutorial
The above is the detailed content of How to check port occupancy in Linux. For more information, please follow other related articles on the PHP Chinese website!