1、lsof -i:端口号
用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:80
[root@2020 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 20292 root 6u IPv4 46938828 0t0 TCP *:http (LISTEN)
nginx 20293 www 6u IPv4 46938828 0t0 TCP *:http (LISTEN)
[root@2020 ~]#
lsof -i:8080:查看8080端口占用 lsof abc.txt:显示开启文件abc.txt的进程 lsof -c abc:显示abc进程现在打开的文件 lsof -c -p 1234:列出进程号为1234的进程所打开的文件 lsof -g gid:显示归属gid的进程情况 lsof +d /usr/local/:显示目录下被进程开启的文件 lsof +D /usr/local/:同上,但是会搜索目录下的目录,时间较长 lsof -d 4:显示使用fd为4的进程 lsof -i -U:显示所有打开的端口和UNIX domain文件
2、netstat -tunlp |grep 端口号
用于查看指定的端口号的进程情况,如查看8000端口的情况,netstat -tunlp |grep 80
查看所有端口占用情况:
[root@2020 ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:63791 0.0.0.0:* LISTEN 1786/redis-server 1
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20292/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 869/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 20292/nginx: master
tcp6 0 0 :::8080 :::* LISTEN 16623/docker-proxy
tcp6 0 0 :::22 :::* LISTEN 869/sshd
tcp6 0 0 :::3306 :::* LISTEN 15845/docker-proxy
udp 0 0 0.0.0.0:68 0.0.0.0:* 598/dhclient
[root@2020 ~]#
查看指定端口占用:8090端口
[root@2020 ~]# netstat -tunlp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20292/nginx: master
tcp6 0 0 :::8080 :::* LISTEN 16623/docker-proxy
[root@2020 ~]#
常用命令:
netstat -ntlp //查看当前所有tcp端口 netstat -ntulp | grep 80 //查看所有80端口使用情况 netstat -ntulp | grep 3306 //查看所有3306端口使用情况
最后修改于 2020-12-30 01:13:15
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

