How to check if the port is occupied by LINUX
What the editor wants to share with you this time is how to check whether the port is occupied by LINUX. The content of the article is rich. Interested friends can learn about it. I hope you can get something after reading this article.
1.netstat-anp | grep port number
As follows, let me take 3306 as an example, netstat-anp | grep 3306 (note here, I operate as an ordinary user, so add sudo. If you operate as a root user, you can view it without adding sudo), as shown in figure 1:
Figure 1
In figure 1, the monitoring status of LISTEN indicates that it has been occupied, and the last column shows that it is occupied by the service mysqld. Check the specific port number. As long as the line as shown in the figure indicates that it is occupied.
2.netstat-nultp (no port number is added here)
This command looks at all the ports that are currently in use, as shown in figure 2:
Figure 2
You can see in the picture that my port 82 is not occupied.
3.netstat-anp | grep 82 to view the usage of port 82, as shown in figure 3:
Figure 3
You can see that there is no LISTEN line, so it means it is not occupied. Note here that the LISTENING shown in the figure does not mean that the port is occupied. Do not be confused with LISTEN. When viewing a specific port, you must see the line tcp, port number and LISTEN to indicate that the port is occupied.
After reading this article on how LINUX checks to see if the port is occupied, if you think the article is well written, you can share it with more people.