Home > Operation and Maintenance > Linux Operation and Maintenance > How to check if a port is occupied in Linux

How to check if a port is occupied in Linux

王林
Release: 2019-12-27 14:15:27
Original
16886 people have browsed it

How to check if a port is occupied in Linux

1. Use the netstat command

netstat  -anp  |grep   端口号
Copy after login

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:

How to check if a port is occupied in Linux

##The above figure mainly shows that the monitoring status is

LISTEN, which means it is occupied. The last column shows that it is occupied by the service mysqld. Check the specific port number.

Online learning video tutorial sharing:

linux video tutorial

2. Use the following command

netstat   -nultp
Copy after login

This command is to view all currently used ports , as shown below:

How to check if a port is occupied in Linux

# It can be seen from the picture that port 82 is not occupied.

3. Use the following command

netstat  -anp  |grep  82
Copy after login
to check the usage of port 82, as shown below:


How to check if a port is occupied in Linux

It can be seen that There is no LISTEN line, so it means 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. One line indicates that the port is occupied.

Recommended related articles and tutorials:

linux tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template