1. netstat命令简介

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

电脑怎么看端口(移动宽带端口查询)(1)

netstat命令简介

电脑怎么看端口(移动宽带端口查询)(2)

2. 查看netstat 所有状态

[root@zcwyou ~]# 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连接

[root@zcwyou ~]# 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. 禁用反向域名解析,加快查询速度

[root@zcwyou ~]# 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 选项持续输出信息。

[root@zcwyou ~]# netstat -ct

6. 常见用法

6.1 查看所有TCP监听端口

[root@zcwyou ~]# netstat -lntp

电脑怎么看端口(移动宽带端口查询)(3)

linux查看所有TCP监听端口

6.2 查看所有的TCP连接情况

[root@zcwyou ~]# netstat -antp

6.3 查看所有UDP连接情况

[root@zcwyou ~]# netstat -anp |sed -n '2p;/^udp/p'

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

[root@zcwyou ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p'

电脑怎么看端口(移动宽带端口查询)(4)

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

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

[root@zcwyou ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p' |wc -l

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

[root@zcwyou ~]# netstat -nap | grep SYN_RECV

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

[root@zcwyou ~]# netstat -nap | grep SYN_RECV |wc -l

6.8 查看网络统计信息

[root@zcwyou ~]# netstat -s