首页 » InfoTech »

用lsof命令查看端口使用情况

2018年9月1日 / 33次阅读
Linux

打开支付宝首页,搜索“529018372”,即可领取红包!可重复领。

特色图片

lsof,List Open Files 列出当前系统打开文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件(lsof强大原因)。所以如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口。因为应用程序打开文件的描述符列表提供了大量关于这个应用程序本身的信息,因此通过lsof工具能够查看这个列表对系统监测以及排错将是很有帮助的。

用lsof命令查看端口使用情况

查看22号端口:

root@iZj6cekasg0jm7xl4v4d36Z:~# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 818 root 3u IPv4 13843 0t0 TCP *:ssh (LISTEN)
sshd 859 root 3u IPv4 14349 0t0 TCP iZj6cekasg0jm7xl4v4d36Z:ssh->183.208.21.117:8173 (ESTABLISHED)
root@iZj6cekasg0jm7xl4v4d36Z:~#

看看著名的80端口的情况:

xinlin@iZ239r252v4Z:~$ sudo lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun 5767 root 17u IPv4 63210876 0t0 TCP 114.215.183.12:55848->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 5767 root 18u IPv4 218325662 0t0 TCP 114.215.183.12:33862->106.11.248.51:http (ESTABLISHED)
AliYunDun 5767 root 21u IPv4 102520665 0t0 TCP 114.215.183.12:44394->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 5767 root 27u IPv4 25871632 0t0 TCP 114.215.183.12:55996->140.205.140.205:http (CLOSE_WAIT)
httpd 7388 root 3u IPv4 188599860 0t0 TCP *:http (LISTEN)
httpd 7595 xinlin 3u IPv4 188599860 0t0 TCP *:http (LISTEN)
AliYunDun 12547 root 17u IPv4 63210876 0t0 TCP 114.215.183.12:55848->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 12547 root 21u IPv4 102520665 0t0 TCP 114.215.183.12:44394->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 12547 root 27u IPv4 25871632 0t0 TCP 114.215.183.12:55996->140.205.140.205:http (CLOSE_WAIT)
xinlin@iZ239r252v4Z:~$

非root用户,命令前加sudo:

xinlin@iZ239r252v4Z:~$ sudo lsof -i
[sudo] password for xinlin:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 705 root 3u IPv4 13659 0t0 TCP *:22 (LISTEN)
wrapper 811 root 5u IPv4 14166 0t0 TCP localhost:32000->localhost:31000 (ESTABLISHED)
ntpd 812 ntp 16u IPv6 13620 0t0 UDP *:ntp
ntpd 812 ntp 17u IPv4 13623 0t0 UDP *:ntp
ntpd 812 ntp 18u IPv4 13627 0t0 UDP localhost:ntp
ntpd 812 ntp 19u IPv4 13629 0t0 UDP iZ239r252v4Z:ntp
ntpd 812 ntp 20u IPv4 13631 0t0 UDP 114.215.183.12:ntp
java 815 root 3u IPv4 13672 0t0 TCP localhost:32000 (LISTEN)
java 815 root 28u IPv4 14162 0t0 TCP localhost:31000->localhost:32000 (ESTABLISHED)
AliYunDun 5767 root 17u IPv4 63210876 0t0 TCP 114.215.183.12:55848->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 5767 root 18u IPv4 218325662 0t0 TCP 114.215.183.12:33862->106.11.248.51:http (ESTABLISHED)
AliYunDun 5767 root 21u IPv4 102520665 0t0 TCP 114.215.183.12:44394->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 5767 root 27u IPv4 25871632 0t0 TCP 114.215.183.12:55996->140.205.140.205:http (CLOSE_WAIT)
httpd 7388 root 3u IPv4 188599860 0t0 TCP *:http (LISTEN)
httpd 7595 xinlin 3u IPv4 188599860 0t0 TCP *:http (LISTEN)
httpd 7595 xinlin 9u IPv4 224320360 0t0 TCP 114.215.183.12:http->183.208.21.117:8577 (ESTABLISHED)
httpd 7595 xinlin 10u IPv4 224320365 0t0 TCP 114.215.183.12:http->123.125.67.212:60962 (ESTABLISHED)
AliYunDun 12547 root 17u IPv4 63210876 0t0 TCP 114.215.183.12:55848->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 12547 root 21u IPv4 102520665 0t0 TCP 114.215.183.12:44394->140.205.140.205:http (CLOSE_WAIT)
AliYunDun 12547 root 27u IPv4 25871632 0t0 TCP 114.215.183.12:55996->140.205.140.205:http (CLOSE_WAIT)
sshd 15940 root 3u IPv4 224317993 0t0 TCP 114.215.183.12:18962->183.208.21.117:8523 (ESTABLISHED)
sshd 15960 xinlin 3u IPv4 224317993 0t0 TCP 114.215.183.12:18962->183.208.21.117:8523 (ESTABLISHED)
xinlin@iZ239r252v4Z:~$

 

本文链接:http://www.maixj.net/ict/lsof-18757
云上小悟 麦新杰(QQ:1093023102)

相关文章

评论是美德

无力满足评论实名制,评论对非实名注册用户关闭,有事QQ:1093023102.


前一篇:
后一篇:

栏目精选

云上小悟,麦新杰的独立博客

Ctrl+D 收藏本页

栏目


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top