1. View all port occupancy
The parameters of the netstat command are described as follows
Column 1 | Column 2 |
---|---|
-t | Specifies to display the TCP port |
-u | Specifies to display the UDP port |
-l | Only display the listening socket (the so-called socket is the program that enables the application to read, write, send and receive communication protocols and data) |
-p | Displays the process identifier and program name, each socket/port belongs to a program. |
-n | Do not perform DNS polling, display IP (can speed up operation) |
1.1 View the port occupancy of the TCP type
- netstat -tln
- netstat -ntpl
1.2 Check the port occupancy of UDP type
- netstat -nupl
1.3 View the port occupancy of TCP and UDP types
- netstat -tunlp
2 View the usage of a given port
- lsof -i: port number
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 in the figure below, the meaning of each column output by lsof is:
column name | significance |
---|---|
COMMAND | The name of the process or how the process was started |
PID | process id |
USER | process owner |
FD | file descriptor |
TYPE | agreement type |
DEVICE | The port number |
SIZE/OFF | offset |
NODE | protocol name |
NAME | node name |
- netstat -tunlp|grep port number
- netstat -ntulp | grep port number
3. Kill the process that occupies the port, and kill it according to the pid
- kill -9 process pid