Linux 端口占用查看

  1. ss查看
ss -lntpd | grep :22

示例:

[root@jk-zhengwu03 ~]# ss -lntpd
Netid  State      Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port
tcp    LISTEN     0      128                                                     *:27017                                                               *:*                   users:(("mongod",pid=5175,fd=11))
tcp    LISTEN     0      128                                                     *:22                                                                  *:*                   users:(("sshd",pid=1399,fd=3))
tcp    LISTEN     0      100                                             127.0.0.1:25                                                                  *:*                   users:(("master",pid=2557,fd=13))
tcp    LISTEN     0      50                                                     :::8080                                                               :::*                   users:(("java",pid=4085,fd=161))
tcp    LISTEN     0      128                                                    :::22                                                                 :::*                   users:(("sshd",pid=1399,fd=4))
  1. netstat

    ```code

netstat -tnlp | grep 22

netstat -nultp

示例:

```shell
[root@jk-zhengwu03 ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      5175/bin/mongod
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1399/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2557/master
tcp6       0      0 :::8080                 :::*                    LISTEN      4085/java
tcp6       0      0 :::22                   :::*                    LISTEN      1399/sshd
  1. lsof

    lsof -i tcp:22
    

示例:

[root@jk-zhengwu03 ~]# lsof -i
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chronyd 1036 chrony    1u  IPv4   9673      0t0  UDP localhost:323
chronyd 1036 chrony    2u  IPv6   9674      0t0  UDP [::1]:323
sshd    1399   root    3u  IPv4  20607      0t0  TCP *:ssh (LISTEN)
sshd    1399   root    4u  IPv6  20609      0t0  TCP *:ssh (LISTEN)
master  2557   root   13u  IPv4   8934      0t0  TCP localhost:smtp (LISTEN)
java    4085   root  161u  IPv6  21140      0t0  TCP *:webcache (LISTEN)
java    4085   root  415u  IPv6  18546      0t0  UDP *:33848
java    4085   root  420u  IPv6  17371      0t0  UDP *:mdns
mongod  5175   root   11u  IPv4  32068      0t0  TCP *:27017 (LISTEN)
sshd    9872   root    3u  IPv4 466519      0t0  TCP jk-zhengwu03.jingcaiwang.cn:ssh->66.1.1.196:59066 (ESTABLISHED)