在Linux下如何查询那个程序占用了指定端口

1、查看占用端口的进程列表
lsof -i:port

[root@localhost ~]# lsof -i:80
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1849  root      6u  IPv4  38588      0t0  TCP *:http (LISTEN)
nginx   1850  www    6u  IPv4  38588      0t0  TCP *:http (LISTEN)
nginx   1851  www    6u  IPv4  38588      0t0  TCP *:http (LISTEN)
nginx   1852  www    6u  IPv4  38588      0t0  TCP *:http (LISTEN)
nginx   1853  www    6u  IPv4  38588      0t0  TCP *:http (LISTEN)

2、查看各个占用端口的程序列表
netstat -lnp –ip

[root@localhost ~]# netstat -lnp –ip
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:3306              0.0.0.0:*                   LISTEN      1714/mysqld
tcp       0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1849/nginx
tcp       0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1000/sshd
udp     0      0 0.0.0.0:750                0.0.0.0:*                               967/portreserve
udp     0      0 0.0.0.0:636                0.0.0.0:*                               967/portreserve

3、查看占用端口的链接的列表
netstat -anp | grep port

[root@localhost ~]# netstat -anp | grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1849/nginx
tcp        0      0 ::ffff:192.168.1.104:8005   :::*                        LISTEN      1754/java
tcp        0      0 :::8009                     :::*                        LISTEN      1754/java
tcp        0      0 :::8080                     :::*                        LISTEN      1754/java
unix  2      [ ]         DGRAM                    10802  1008/crond

版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《在Linux下如何查询那个程序占用了指定端口》
文章链接:https://zhuji.vsping.com/3051.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。