天天看点

linux 端口占用查看_Linux怎么查看被占用的端口

请关注本头条号,每天坚持更新原创干货技术文章。

如需学习视频,请在微信搜索公众号“智传网优”直接开始自助视频学习

1. netstat命令简介

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。

linux 端口占用查看_Linux怎么查看被占用的端口

netstat命令简介

linux 端口占用查看_Linux怎么查看被占用的端口

2. 查看netstat 所有状态

[[email protected] ~]# netstat -a
           

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 my_public_ip:9016 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9017 0.0.0.0:* LISTEN

tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9018 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:pptp 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9019 0.0.0.0:* LISTEN

3. 查看所有TCP连接

[[email protected] ~]# netstat -at
           

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 my_public_ip:9016 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9017 0.0.0.0:* LISTEN

tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9018 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:pptp 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9019 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:tambora 0.0.0.0:* LISTEN

tcp 0 0 my_public:etlservicemgr 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:dynamid 0.0.0.0:* LISTEN

tcp 0 0 my_public_ip:9003 0.0.0.0:* LISTEN

4. 禁用反向域名解析,加快查询速度

[[email protected] ~]# netstat -ant
           

tcp 0 0 113.105.164.151:42342 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:49472 202.46.36.30:9001 ESTABLISHED

tcp 0 0 113.105.164.151:43470 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:43576 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:9001 120.84.140.61:6290 FIN_WAIT2

tcp 0 0 113.105.164.151:9015 183.14.29.69:6809 FIN_WAIT2

tcp 0 0 113.105.164.151:35424 202.46.36.30:9002 CLOSE_WAIT

tcp 0 0 113.105.164.151:38074 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:9001 118.112.75.246:2710 FIN_WAIT2

tcp 0 0 113.105.164.151:45124 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:37202 202.46.36.30:9001 CLOSE_WAIT

tcp 0 0 113.105.164.151:52640 202.46.36.30:9001 CLOSE_WAIT

5. 持续刷新信息

我们可以使用 netstat 的 -c 选项持续输出信息。

[[email protected] ~]# netstat -ct
           

6. 常见用法

6.1 查看所有TCP监听端口

[[email protected] ~]# netstat -lntp
           
linux 端口占用查看_Linux怎么查看被占用的端口

linux查看所有TCP监听端口

6.2 查看所有的TCP连接情况

[[email protected] ~]# netstat -antp
           

6.3 查看所有UDP连接情况

[[email protected] ~]# netstat -anp |sed -n '2p;/^udp/p'
           

6.4 查看所有已经建立的TCP连接

[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p'
           
linux 端口占用查看_Linux怎么查看被占用的端口

linux查看所有已经建立的TCP连接

6.5 查看系统当前TCP连接数:

[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p' |wc -l
           

6.6 查看TCP半开连接,正常情况下,应该看不到有数据

[[email protected] ~]# netstat -nap | grep SYN_RECV
           

6.7 查看TCP半开连接数,正常情况下应该为0

[[email protected] ~]# netstat -nap | grep SYN_RECV |wc -l
           

6.8 查看网络统计信息

[[email protected] ~]# netstat -s
           

继续阅读