1.netstat -anp |grep Port number
I take 3306 as an example, netstat -anp |grep 3306 (Note here, I am operating as a normal user, so I added sudo. If I am operating as a root user, I can view it without adding sudo)
In the figure, we mainly look at the monitoring status for the LISTEN table , which indicates that it has been occupied. The last column shows that it is occupied by the service mysqld. Check the specific port number. As long as there is a row like the picture, it means that it is occupied.
2.netstat -nultp (No need to add port number here)
This command is to view all currently used ports,
You can see from the picture that my port 82 is not occupied
3.netstat -anp |grep 82 Check the usage of port 82,
It can be seen that there is no LISTEN line , so it means that it is not occupied. Note here that the LISTENING shown in the picture does not mean that the port is occupied. Do not confuse it with LISTEN. When viewing the specific port, you must see the tcp, port number, and LISTEN lines to indicate that the port is occupied
The above is the detailed content of How to check if a port is occupied in LINUX. For more information, please follow other related articles on the PHP Chinese website!