下面分析在大多數 Linux主要發行版本中提供的一些網絡工具,包括 netstat、nfsstat、 tcpdump、 ethtool、 snmp、 ifport、 ifconfig、 route、 arp、 ping、 traceroute、 host以及nslookup等 。web
系統和網絡管理員天天都會使用其中的某些工具。諸如 ping、 route、 arp、 traceroute、ethtool及 tcpdump之類的工具經常使用於斷定網絡問題。 這些工具描述以下:shell
[solarflar@localhost ~]$ netstat Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 192.168.75.189:ssh 172.29.8.150:51963 TIME_WAIT tcp 0 0 192.168.75.189:ssh 192.168.194.59:48183 ESTABLISHED tcp 0 52 192.168.75.189:ssh 172.29.8.150:52999 ESTABLISHED tcp 0 0 192.168.75.189:ssh 192.168.194.55:19001 ESTABLISHED tcp 0 0 192.168.75.189:ssh 192.168.194.55:17796 ESTABLISHED Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ] DGRAM 29748 /run/systemd/shutdownd unix 2 [ ] DGRAM 11475 /run/systemd/notify unix 5 [ ] DGRAM 11496 /run/systemd/journal/socket unix 16 [ ] DGRAM 11498 /dev/log unix 3 [ ] STREAM CONNECTED 37002 /run/systemd/journal/stdout unix 3 [ ] STREAM CONNECTED 23698 /run/systemd/journal/stdout第1列顯示了 socket的協議系列, 它一般是 tcp(transport control protocol, 傳輸控制協議)、 udp(user datagram protocol, 用戶數據報協議)或 unix(UNIX domain socket, UNIX域套接字);
[solarflar@localhost ~]$ netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eno1 1500 2034333467 0 182 0 3548944453 0 0 0 BMRU eno2 1500 0 0 0 0 0 0 0 0 BMU eno3 1500 0 0 0 0 0 0 0 0 BMU eno4 1500 0 0 0 0 0 0 0 0 BMU enp131s0 1500 1591418974 0 52118 0 486169278 0 0 0 BMRU enp131s0 1500 0 0 0 0 0 0 0 0 BMU lo 65536 594975131 0 0 0 594975131 0 0 0 LRU
[solarflar@localhost ~]$ netstat -s Ip: 4603736451 total packets received 0 forwarded 0 incoming packets discarded 4423014584 incoming packets delivered 4398660228 requests sent out 42782 outgoing packets dropped 22 dropped because of missing route 36615113 reassemblies required 7960999 packets reassembled ok 1967473 fragments received ok 9530756 fragments created Icmp: 1236458 ICMP messages received 1826 input ICMP message failed. ICMP input histogram: destination unreachable: 1236301 echo requests: 71 echo replies: 74 timestamp request: 4 address mask request: 8 405465 ICMP messages sent 0 ICMP messages failed ICMP output histogram: destination unreachable: 405135 echo request: 255 echo replies: 71 timestamp replies: 4 IcmpMsg: InType0: 74 InType3: 1236301 InType8: 71 InType13: 4 InType17: 8 OutType0: 71 OutType3: 405135 OutType8: 255 OutType14: 4 Tcp: 554771 active connections openings 5422 passive connection openings 551155 failed connection attempts 1918 connection resets received 6 connections established 59059673 segments received 69625408 segments send out 24976 segments retransmited 6 bad segments received. 70797 resets sent InCsumErrors: 1 Udp: 4325339161 packets received 999602 packets to unknown port received. 396416917 packet receive errors 4345291695 packets sent 10913928 receive buffer errors 37346 send buffer errors UdpLite: TcpExt: 32 invalid SYN cookies received 36 resets received for embryonic SYN_RECV sockets 73 packets pruned from receive queue because of socket buffer overrun 4652 TCP sockets finished time wait in fast timer 169068 delayed acks sent 36 delayed acks further delayed because of locked socket Quick ack mode was activated 3651 times 26222704 packets directly queued to recvmsg prequeue. 3711962702 bytes directly in process context from backlog 15106819553 bytes directly received in process context from prequeue 2655495 packet headers predicted 31357215 packets header predicted and directly queued to user 3062089 acknowledgments not containing data payload received 31242645 predicted acknowledgments 2010 times recovered from packet loss by selective acknowledgements Detected reordering 2 times using FACK 2 congestion windows fully recovered without slow start 308 congestion windows recovered without slow start by DSACK 267 congestion windows recovered without slow start after partial ack TCPLostRetransmit: 226 12 timeouts after SACK recovery 1 timeouts in loss state 4619 fast retransmits 3282 forward retransmits 413 retransmits in slow start 518 other TCP timeouts TCPLossProbes: 15920 TCPLossProbeRecovery: 14042 41 SACK retransmits failed 7152 packets collapsed in receive queue due to low socket buffer 4731 DSACKs sent for old packets 2 DSACKs sent for out of order packets 15907 DSACKs received 11 DSACKs for out of order packets received 10 connections reset due to unexpected data 42 connections reset due to early user close 206 connections aborted due to timeout TCPDSACKIgnoredOld: 1 TCPDSACKIgnoredNoUndo: 13716 TCPSpuriousRTOs: 40 TCPSackShifted: 19573 TCPSackMerged: 2838 TCPSackShiftFallback: 15102 TCPRetransFail: 6 TCPRcvCoalesce: 172790 TCPOFOQueue: 62042 TCPOFOMerge: 2 TCPChallengeACK: 199 TCPSYNChallenge: 5 TCPAutoCorking: 133696 TCPFromZeroWindowAdv: 20 TCPToZeroWindowAdv: 20 TCPWantZeroWindowAdv: 1589 TCPSynRetrans: 33 TCPOrigDataSent: 60622666 TCPHystartTrainDetect: 154 TCPHystartTrainCwnd: 3092 TCPHystartDelayDetect: 21 TCPHystartDelayCwnd: 899 TCPACKSkippedSeq: 197 TCPACKSkippedChallenge: 1 IpExt: InMcastPkts: 3045103079 OutMcastPkts: 2727644667 InBcastPkts: 16567 InOctets: 1654553951951 OutOctets: 351194071831 InMcastOctets: 1058583515712 OutMcastOctets: 221466960723 InBcastOctets: 2639362 InNoECTPkts: 4603779373 InECT0Pkts: 30 [solarflar@localhost ~]$另外, 網絡通訊涉及到繁重的中斷處理。 所以, 經過與 netstat工具相結合, 可使用 vmstat來捕獲中斷數目,使用 sar來肯定中斷處理操做的散佈狀況。
[solarflar@localhost ~]$ nfsstat Server rpc stats: calls badcalls badclnt badauth xdrcall 0 0 0 0 0