Linux的netstat命令详解
程序员文章站
2022-06-25 09:35:16
目录linux的netstat命令1、tcp连接状态详解2、命令格式3、命令选项4、列出所有端口(包含tcp和udp)4、列出所有tcp端口5、列出所有udp端口6、列出所有处于监听状态的 socke...
linux的netstat命令
1、tcp连接状态详解
- listen: 侦听来自远方的tcp端口的连接请求
- syn-sent: 再发送连接请求后等待匹配的连接请求
- syn-received:再收到和发送一个连接请求后等待对方对连接请求的确认
- established: 代表一个打开的连接
- fin-wait-1: 等待远程tcp连接中断请求,或先前的连接中断请求的确认
- fin-wait-2: 从远程tcp等待连接中断请求
- close-wait: 等待从本地用户发来的连接中断请求
- closing: 等待远程tcp对连接中断的确认
- last-ack: 等待原来的发向远程tcp的连接中断请求的确认
- time-wait: 等待足够的时间以确保远程tcp接收到连接中断请求的确认
- closed: 没有任何连接状态
2、命令格式
netstat(选项)
3、命令选项
- -a或–all:显示所有连线中的socket;
- -a<网络类型>或–<网络类型>:列出该网络类型连线中的相关地址;
- -c或–continuous:持续列出网络状态;
- -c或–cache:显示路由器配置的快取信息;
- -e或–extend:显示网络其他相关信息;
- -f或–fib:显示fib;
- -g或–groups:显示多重广播功能群组组员名单;
- -h或–help:在线帮助;
- -i或–interfaces:显示网络界面信息表单;
- -l或–listening:显示监控中的服务器的socket;
- -m或–masquerade:显示伪装的网络连线;
- -n或–numeric:直接使用ip地址,而不通过域名服务器;
- -n或–netlink或–symbolic:显示网络硬件外围设备的符号连接名称;
- -o或–timers:显示计时器;
- -p或–programs:显示正在使用socket的程序识别码和程序名称;
- -r或–route:显示routing table;
- -s或–statistice:显示网络工作信息统计表;
- -t或–tcp:显示tcp传输协议的连线状况;
- -u或–udp:显示udp传输协议的连线状况;
- -v或–verbose:显示指令执行过程;
- -v或–version:显示版本信息;
- -w或–raw:显示raw传输协议的连线状况;
- -x或–unix:此参数的效果和指定"-a unix"参数相同;
- –ip或–inet:此参数的效果和指定"-a inet"参数相同。
4、列出所有端口(包含tcp和udp)
> netstat -a
4、列出所有tcp端口
> netstat -at
5、列出所有udp端口
> netstat -au
6、列出所有处于监听状态的 sockets
> netstat -l
7、只列出所有监听tcp端口
> netstat -lt
8、只列出所有监听udp端口
> netstat -lu
9、只列出所有监听unix端口
> netstat -lx
10显示所有端口的统计信息
> netstat -s ip: 1007495197 total packets received 0 forwarded 582 with unknown protocol 0 incoming packets discarded 1007422115 incoming packets delivered icmp: 66583265 icmp messages received 63899 input icmp message failed. incsumerrors: 384 icmp input histogram: destination unreachable: 115410 timeout in transit: 12840 source quenches: 11 redirects: 563 echo requests: 66453453 echo replies: 152 timestamp request: 438 address mask request: 4 66987000 icmp messages sent 0 icmp messages failed icmp output histogram: destination unreachable: 533106 echo request: 4 echo replies: 66453453 timestamp replies: 437 icmpmsg: intype0: 152 intype3: 115410 intype4: 11 intype5: 563 ipext: innoroutes: 15 inmcastpkts: 1291307 inoctets: 211446050816 outoctets: 481070069194
11、显示tcp端口的统计信息
> netstat -st icmpmsg: intype0: 152 intype3: 115410 intype4: 11 intype5: 563 intype8: 66453492 tcp: 55437641 active connections openings 35899081 passive connection openings 552243 failed connection attempts 753118 connection resets received 7 connections established udplite: tcpext: 162052 syn cookies sent 621 syn cookies received 4998179 invalid syn cookies received 551915 resets received for embryonic syn_recv sockets ipext: innoroutes: 15 inmcastpkts: 1291308 inoctets: 211446303015 outoctets: 481070459735 inmcastoctets: 46487088
12、显示udp端口的统计信息
> netstat -su icmpmsg: intype0: 152 intype3: 115410 intype4: 11 intype5: 563 intype8: 66453594 intype11: 12840 intype13: 438 intype17: 4 intype37: 3 intype165: 7 outtype0: 66453594 outtype3: 533106 outtype8: 4 outtype14: 437 udp: 17941589 packets received 637146 packets to unknown port received. 1649 packet receive errors 17977050 packets sent 0 receive buffer errors 0 send buffer errors incsumerrors: 1640 udplite: ipext: innoroutes: 15 inmcastpkts: 1291310 inoctets: 211446802283 outoctets: 481071405083 inmcastoctets: 46487160 innoectpkts: 1009629627 inect1pkts: 9955 inect0pkts: 1987096 incepkts: 94039
13、在netstat输出中显示 pid 和进程名称
> netstat -pt
14、在netstat输出中不显示主机,端口和用户名(host, port or user)
> netstat -an
15、持续输出netstat信息
每隔一秒输出网络信息
> netstat -c
16、显示核心路由信息
> netstat -r kernel ip routing table destination gateway genmask flags mss window irtt iface default gateway 0.0.0.0 ug 0 0 0 eth0 link-local 0.0.0.0 255.255.0.0 u 0 0 0 eth0 172.16.0.0 0.0.0.0 255.255.240.0 u 0 0 0 eth0
17、使用netstat -rn显示数字格式,不查询主机名称。
> netstat -rn kernel ip routing table destination gateway genmask flags mss window irtt iface 0.0.0.0 172.16.0.1 0.0.0.0 ug 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 u 0 0 0 eth0 172.16.0.0 0.0.0.0 255.255.240.0 u 0 0 0 eth0
18、找出程序运行的端口
> netstat -tunlp | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 4400/sshd
19、找出运行在指定端口的进程
> netstat -an | grep ":80" tcp 0 0 0.0.0.0:80 0.0.0.0:* listen tcp 0 0 172.16.0.9:80 185.191.171.12:9380 time_wait tcp 0 0 172.16.0.9:80 185.191.171.26:52418 time_wait tcp 0 3450 172.16.0.9:80 185.191.171.37:25108 fin_wait1 tcp 0 0 172.16.0.9:80 185.191.171.37:55096 time_wait tcp 0 0 172.16.0.9:80 144.76.176.171:27832 time_wait tcp 0 0 172.16.0.9:80 118.126.124.7:11127 time_wait tcp 0 0 172.16.0.9:46628 169.254.0.55:8080 time_wait tcp 0 0 172.16.0.9:80 144.76.176.171:23812 established
20、通过端口找进程id
> netstat -tunlp | grep 80 | awk '{print $7}' | cut -d/ -f1 21323
21、显示网络接口列表
> netstat -i kernel interface table iface mtu rx-ok rx-err rx-drp rx-ovr tx-ok tx-err tx-drp tx-ovr flg docker0 1500 0 0 0 0 0 0 0 0 bmu eth0 1450 462305568 0 0 0 276046945 0 0 0 bmru lo 65536 7204971 0 0 0 7204971 0 0 0 lru vpn_abi 1500 229612389 0 1023383 0 146640133 0 956 0 bmru
22、统计tcp各种状态列表
> netstat -n | awk '/^tcp/{++s[$nf]}end{for(i in s) print i,s[i]}' established 7 fin_wait2 13 time_wait 18
以上就是linux的netstat命令详解的详细内容,更多关于linux netstat命令的资料请关注其它相关文章!希望大家以后多多支持!