How to check if a port is occupied in CentOS

藏色散人
Release: 2020-12-28 16:04:23
forward
14918 people have browsed it

The following column centos tutorial will introduce to you how to check whether the port is occupied in CentOS. I hope it will be helpful to friends in need!

How to check if a port is occupied in CentOS

CentOSCheck whether a port is occupied
This article introduces the method of checking whether a port is occupied in Linux, and the use of netstat command Tips, interested friends can refer to it.

Use the command:

netstat -tunlp
Copy after login

will display all ports and all corresponding programs. Use the grep pipe to filter out the desired key fields.

Programs related to port 22 occupancy:

Code example:

[root@leiwan tmp]# netstat -tunlp |grep 22 
tcp        0      0 0.0.0.0:42957               0.0.0.0:*                   LISTEN      2230/rpc.statd 
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2443/sshd 
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2292/cupsd 
tcp        0      0 :::22                       :::*                        LISTEN      2443/sshd 
tcp        0      0 ::1:631                     :::*                        LISTEN      2292/cupsd 
tcp        0      0 :::57609                    :::*                        LISTEN      2230/rpc.statd 
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               2211/avahi-daemon 
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2292/cupsd 
udp        0      0 0.0.0.0:37167               0.0.0.0:*                               2230/rpc.statd 
udp        0      0 0.0.0.0:52291               0.0.0.0:*                               2211/avahi-daemon 
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               2207/dhclient 
udp        0      0 0.0.0.0:710                 0.0.0.0:*                               2230/rpc.statd 
udp        0      0 :::39834                    :::*                                    2230/rpc.statd
Copy after login

Check the occupancy of a certain port: lsof -i:port number

Code example:

1  [root@www ~]# lsof -i:21 
3  COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME 
4  pure-ftpd 2651 root 4u IPv4 7047 TCP *:ftp (LISTEN) 
5  pure-ftpd 2651 root 5u IPv6 7048 TCP *:ftp (LISTEN)
Copy after login

This shows that port 21 is being used by pure-ftpd and the status is listen.

The above is the detailed content of How to check if a port is occupied in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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