Home > Article > Operation and Maintenance > How to check if a port is occupied in Linux
1. Use the netstat
command
netstat -anp |grep 端口号
as follows, taking 3306 as an example, netstat -anp |grep 3306
( Note here, the following is operated by an ordinary user, so sudo is added. If it is operated by the root user, you can view it without adding sudo), as shown in Figure 1:
LISTEN, which means it is occupied. The last column shows that it is occupied by the service mysqld. Check the specific port number.
netstat -nultpThis command is to view all currently used ports , as shown below: # It can be seen from the picture that port 82 is not occupied. 3. Use the following command
netstat -anp |grep 82to check the usage of port 82, as shown below:
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. One line indicates 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!