How to check whether a port is occupied in linux system

How to check whether the port is occupied in linux

insert image description here

1.netstat -anp | grep port number

  1. As follows, I take 3306 as an example, netstat -anp |grep 3306 as shown below:

  2. In the figure, the monitoring status is LISTEN, which means it is already occupied. The last column shows that it is occupied by the service mysqld. Check the specific port number. As long as there is a line like the picture, it means it is occupied.

2.netstat -nultp (no need to add port number here)

  1. This command is to view all currently used ports, as shown in the figure below:
    insert image description here
  2. It can be seen from the picture that my port 89 is not occupied

3. Netstat -anp |grep 89 to view the usage of port 89, as shown below:

insert image description here

  1. It can be seen that there is no line of LISTEN, so it means that it is not occupied. Note here that the LISTENING shown in the figure does not mean that the port is occupied. Do not confuse it with LISTEN. When viewing a specific port, you must see the line tcp, port number, and LISTEN to indicate that the port is occupied.

Guess you like

Origin blog.csdn.net/weixin_44975322/article/details/121998050