电脑怎么看端口是否被占用 电脑怎么看端口关闭情况



文章插图
电脑怎么看端口是否被占用 电脑怎么看端口关闭情况

文章插图
1. netstat命令简介
Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等 。
netstat命令简介
2. 查看netstat 所有状态
[[email protected] ~]# netstat -aActive 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 -atActive 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 -anttcp 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 -ct6. 常见用法
6.1 查看所有TCP监听端口
[[email protected] ~]# netstat -lntp
linux查看所有TCP监听端口
6.2 查看所有的TCP连接情况
[[email protected] ~]# netstat -antp6.3 查看所有UDP连接情况
[[email protected] ~]# netstat -anp |sed -n '2p;/^udp/p'6.4 查看所有已经建立的TCP连接
[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p'
linux查看所有已经建立的TCP连接
6.5 查看系统当前TCP连接数:
[[email protected] ~]# netstat -antp |sed -n '2p;/ESTABLISHED/p' |wc -l6.6 查看TCP半开连接,正常情况下,应该看不到有数据
[[email protected] ~]# netstat -nap | grep SYN_RECV6.7 查看TCP半开连接数,正常情况下应该为0
[[email protected] ~]# netstat -nap | grep SYN_RECV |wc -l6.8 查看网络统计信息
【电脑怎么看端口是否被占用 电脑怎么看端口关闭情况】[[email protected] ~]# netstat -s