-a :all,表示列出所有的连接,服务监听,Socket资料
-t :tcp,列出tcp协议的服务
-u :udp,列出udp协议的服务
-n :port number, 用端口号来显示
-l :listening,列出当前监听服务
-p :program,列出服务程序的PID(显示pid)
-c : 持续的输出
-s : 显示统计信息
-i :显示网络设备的信息(建议使用ifconfig命令得到更丰富的数据)
举例:
-
netstat
-
查看监听端口并显示pid
- 统计TCP处于每个状态的数目
netstat -ant | awk '$1~/tcp/{a[$6]++} END{for(i in a) print i,a[i]}'
-
显示网络设备信息
- 显示统计信息
$netstat -s
Ip:
11171317 total packets received
0 forwarded
0 incoming packets discarded
11171317 incoming packets delivered
10926797 requests sent out
Icmp:
2499 ICMP messages received
151 input ICMP message failed.
ICMP input histogram:
destination unreachable: 315
timeout in transit: 180
echo requests: 2004
2007 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 3
echo replies: 2004
IcmpMsg:
InType3: 315
InType8: 2004
InType11: 180
OutType0: 2004
OutType3: 3
Tcp:
635225 active connections openings
998235 passive connection openings
2970 failed connection attempts
165 connection resets received
168 connections established
11161584 segments received
13571031 segments send out
26505 segments retransmited
4 bad segments received.
21357 resets sent
Udp:
7231 packets received
3 packets to unknown port received.
0 packet receive errors
24552 packets sent
UdpLite:
TcpExt:
10 invalid SYN cookies received
1 resets received for embryonic SYN_RECV sockets
1081835 TCP sockets finished time wait in fast timer
155490 delayed acks sent
367 delayed acks further delayed because of locked socket
Quick ack mode was activated 62 times
12730 packets directly queued to recvmsg prequeue.
2301002 packets directly received from backlog
47619146 packets directly received from prequeue
1699670 packets header predicted
37328 packets header predicted and directly queued to user
3500729 acknowledgments not containing data received
1806591 predicted acknowledgments
58 times recovered from packet loss due to SACK data
Detected reordering 3 times using FACK
Detected reordering 2 times using SACK
Detected reordering 12 times using time stamp
1 congestion windows fully recovered
12 congestion windows partially recovered using Hoe heuristic
TCPDSACKUndo: 228
66 congestion windows recovered after partial ack
TCPLostRetransmit: 13
1 timeouts in loss state
184 fast retransmits
7 forward retransmits
88 retransmits in slow start
9402 other TCP timeouts
TCPLossProbes: 1326
TCPLossProbeRecovery: 624
3 sack retransmits failed
62 DSACKs sent for old packets
1815 DSACKs received
3 connections reset due to unexpected data
17 connections reset due to early user close
263 connections aborted due to timeout
TCPDSACKIgnoredNoUndo: 547
TCPSpuriousRTOs: 15
TCPSackShifted: 97
TCPSackMerged: 131
TCPSackShiftFallback: 276
TCPRcvCoalesce: 260510
TCPOFOQueue: 3253
TCPChallengeACK: 4
TCPSYNChallenge: 4
TCPWantZeroWindowAdv: 6
TCPSynRetrans: 23029
TCPOrigDataSent: 7723106
TCPHystartTrainDetect: 515
TCPHystartTrainCwnd: 10849
TCPHystartDelayDetect: 1
TCPHystartDelayCwnd: 29
IpExt:
InOctets: -1230225412
OutOctets: -1341641495
InNoECTPkts: 11171134
InECT1Pkts: 4
InECT0Pkts: 176
InCEPkts: 3
参考
[netstat(http://www.cnblogs.com/peida/archive/2013/03/08/2949194.html)