运维必备!linux查看端口占用情况

做linux运维常常于见的问题!
Mar 21 21:25:02 VM_0_9_centos httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Mar 21 21:25:02 VM_0_9_centos httpd: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Mar 21 21:25:02 VM_0_9_centos httpd: no listening sockets available, shutting down
从日志文件可以明显的看出是端口问题

一、Linux如何查看端口和关闭某个端口
1、lsof -i:端口号 用于查看某一端口的占用情况,比如查看80端口使用情况,

[root@VM_0_9_centos html]# lsof -i:80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   25352  root    6u  IPv4  82362      0t0  TCP *:http (LISTEN)
nginx   25353 nginx    6u  IPv4  82362      0t0  TCP *:http (LISTEN)

可以看到80端口已经被web服务程序nginx占用
关闭某个端口用 kill -9 pid

[root@VM_0_9_centos html]# kill -9 25352
[root@VM_0_9_centos html]# kill -9 25353

2、netstat -tunlp |grep 端口号,用于查看指定的端口号的进程情况,如查看8000端口的情况,netstat -tunlp |grep 8000
复制代码

查看所有端口的使用情况

[root@VM_0_9_centos html]# netstat -tunlp 
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:111                 0.0.0.0:*                   LISTEN      4814/rpcbind        
tcp        0      0 0.0.0.0:5908                0.0.0.0:*                   LISTEN      25492/qemu-kvm      
tcp        0      0 0.0.0.0:6996                0.0.0.0:*                   LISTEN      22065/lwfs          
tcp        0      0 192.168.122.1:53            0.0.0.0:*                   LISTEN      38296/dnsmasq       
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      5278/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      5013/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      5962/master         
tcp        0      0 0.0.0.0:8666                0.0.0.0:*                   LISTEN      44868/lwfs          
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      22065/lwfs     

查看指定端口netstat -tunlp | grep 8000

[root@VM_0_9_centos html]# netstat -tunlp | grep 8000
tcp        0      0 0.0.0.0:8000                0.0.0.0:*                   LISTEN      22065/lwfs          
发布了17 篇原创文章 · 获赞 16 · 访问量 2698

猜你喜欢

转载自blog.csdn.net/qq_45714272/article/details/105017863
今日推荐