Linux下常用网络命令总结
你可以使用以下任何一个命令:
nstat 命令 : 网络统计工具
键入以下命令:
输出样例:
#kernel
ipinreceives 133243 0.0
ipindelivers 133243 0.0
ipoutrequests 92904 0.0
icmpouterrors 97 0.0
icmpouttimeexcds 97 0.0
icmpmsgouttype3 97 0.0
tcpactiveopens 538 0.0
tcpestabresets 56 0.0
tcpinsegs 129837 0.0
tcpoutsegs 89720 0.0
tcpretranssegs 42 0.0
tcpoutrsts 704 0.0
udpindatagrams 3255 0.0
udpnoports 97 0.0
udpoutdatagrams 3270 0.0
ip6outnoroutes 206 0.0
tcpexttw 141 0.0
tcpextdelayedacks 508 0.0
tcpextdelayedacklocked 1 0.0
tcpextdelayedacklost 42 0.0
tcpexttcphphits 117659 0.0
tcpexttcppureacks 2158 0.0
tcpexttcphpacks 605 0.0
tcpexttcpsackrecovery 1 0.0
tcpexttcplossundo 16 0.0
tcpexttcpsackfailures 4 0.0
tcpexttcpfastretrans 1 0.0
tcpexttcpslowstartretrans 3 0.0
tcpexttcptimeouts 33 0.0
tcpexttcpdsackoldsent 40 0.0
tcpexttcpdsackrecv 5 0.0
tcpexttcpabortondata 120 0.0
tcpexttcpabortonclose 55 0.0
tcpexttcpsackshiftfallback 9 0.0
ipextinoctets 180131682 0.0
ipextoutoctets 7289106 0.0
ss 命令 : 查询套接字工具
要查看统计汇总, 输入:
输出样例:
total: 786 (kernel 804)
tcp: 65 (estab 40, closed 7, orphaned 0, synrecv 0, timewait 6/0), ports 56
transport total ip ipv6
* 804 - -
raw 1 1 0
udp 12 9 3
tcp 58 52 6
inet 71 62 9
frag 0 0 0
netstat 命令 : 不错的显示套接字信息的旧工具
查看所有网络端口以及汇总信息表,输入:
输出样例:
kernel interface table
iface mtu met rx-ok rx-err rx-drp rx-ovr tx-ok tx-err tx-drp tx-ovr flg
eth0 1500 0 941022 0 0 0 688165 0 0 0 bmru
lo 16436 0 9304 0 0 0 9304 0 0 0 lru
ppp0 1496 0 3784 0 0 0 4177 0 0 0 mopru
查看每个协议的汇总统计信息,输入:
输出样例:
ip:
1092065 total packets received
0 forwarded
0 incoming packets discarded
1091681 incoming packets delivered
798913 requests sent out
895 dropped because of missing route
759 reassemblies required
375 packets reassembled ok
icmp:
17 icmp messages received
0 input icmp message failed.
icmp input histogram:
timeout in transit: 8
echo replies: 9
1747 icmp messages sent
0 icmp messages failed
icmp output histogram:
destination unreachable: 1730
echo request: 17
icmpmsg:
intype0: 9
intype11: 8
outtype3: 1730
outtype8: 17
tcp:
4822 active connections openings
1129 passive connection openings
457 failed connection attempts
165 connection resets received
7 connections established
1062519 segments received
771394 segments send out
7158 segments retransmited
6 bad segments received.
2578 resets sent
udp:
20846 packets received
1730 packets to unknown port received.
0 packet receive errors
19242 packets sent
udplite:
tcpext:
71 invalid syn cookies received
8 resets received for embryonic syn_recv sockets
142 packets pruned from receive queue because of socket buffer overrun
2109 tcp sockets finished time wait in fast timer
84 packets rejects in established connections because of timestamp
19454 delayed acks sent
6 delayed acks further delayed because of locked socket
quick ack mode was activated 7306 times
1 packets directly queued to recvmsg prequeue.
1 bytes directly received in process context from prequeue
823921 packet headers predicted
24412 acknowledgments not containing data payload received
10150 predicted acknowledgments
242 times recovered from packet loss by selective acknowledgements
33 congestion windows recovered without slow start by dsack
335 congestion windows recovered without slow start after partial ack
336 tcp data loss events
tcplostretransmit: 35
1 timeouts after reno fast retransmit
156 timeouts after sack recovery
116 timeouts in loss state
461 fast retransmits
5 forward retransmits
608 retransmits in slow start
2073 other tcp timeouts
62 sack retransmits failed
43074 packets collapsed in receive queue due to low socket buffer
8499 dsacks sent for old packets
101 dsacks sent for out of order packets
308 dsacks received
9 dsacks for out of order packets received
427 connections reset due to unexpected data
122 connections reset due to early user close
28 connections aborted due to timeout
tcpdsackignoredold: 3
tcpdsackignorednoundo: 60
tcpspuriousrtos: 4
tcpsackshifted: 282
tcpsackmerged: 740
tcpsackshiftfallback: 1017
ipext:
inmcastpkts: 47
outmcastpkts: 51
inbcastpkts: 1
inoctets: 1341508973
outoctets: 72525352
inmcastoctets: 8649
outmcastoctets: 7519
inbcastoctets: 328
ip / ifconfig 命令 : 配置或者显示网络端口信息
键入以下命令:
或者
或者
eth0 link encap:ethernet hwaddr b8:ac:6f:65:31:e5
inet addr:192.168.1.5 bcast:192.168.1.255 mask:255.255.255.0
inet6 addr: fe80::baac:6fff:fe65:31e5/64 scope:link
up broadcast running multicast mtu:1500 metric:1
rx packets:966334 errors:0 dropped:0 overruns:0 frame:0
tx packets:703297 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
rx bytes:1186255648 (1.1 gib) tx bytes:73968238 (70.5 mib)
interrupt:17
lo link encap:local loopback
inet addr:127.0.0.1 mask:255.0.0.0
inet6 addr: ::1/128 scope:host
up loopback running mtu:16436 metric:1
rx packets:9666 errors:0 dropped:0 overruns:0 frame:0
tx packets:9666 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
rx bytes:1399578 (1.3 mib) tx bytes:1399578 (1.3 mib)
ppp0 link encap:point-to-point protocol
inet addr:10.1.11.70 p-t-p:10.0.31.18 mask:255.255.255.255
up pointopoint running noarp multicast mtu:1496 metric:1
rx packets:3784 errors:0 dropped:0 overruns:0 frame:0
tx packets:4177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
rx bytes:2400265 (2.2 mib) tx bytes:275983 (269.5 kib)
显示网络端口统计信息,输入:
输出样例:
1: lo: mtu 16436 qdisc noqueue state unknown
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
rx: bytes packets errors dropped overrun mcast
1444187 9960 0 0 0 0
tx: bytes packets errors dropped carrier collsns
1444187 9960 0 0 0 0
2: eth0: mtu 1500 qdisc mq state up qlen 1000
link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
rx: bytes packets errors dropped overrun mcast
1221956483 991501 0 0 0 24
tx: bytes packets errors dropped carrier collsns
75623937 720272 0 0 0 0
3: wlan0: mtu 1500 qdisc noop state down qlen 1000
link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
rx: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
tx: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
4: pan0: mtu 1500 qdisc noop state down
link/ether 4a:c7:5f:0e:8e:d8 brd ff:ff:ff:ff:ff:ff
rx: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
tx: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
8: ppp0: mtu 1496 qdisc pfifo_fast state unknown qlen 3
link/ppp
rx: bytes packets errors dropped overrun mcast
2419881 3848 0 0 0 0
tx: bytes packets errors dropped carrier collsns
284151 4287 0 0 0 0
sar 命令: 显示网络统计信息
输入以下命令 (你需要 通过sysstat包安装并启用sar):
linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) tuesday 13 march 2012 _x86_64_ (2 cpu)
12:00:01 cdt iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
12:10:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:10:01 cdt eth0 127.13 121.32 95.45 18.34 0.00 0.00 0.00
12:10:01 cdt eth1 98.48 110.62 16.72 96.33 0.00 0.00 0.00
12:20:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:20:01 cdt eth0 139.95 133.41 106.30 19.95 0.00 0.00 0.00
12:20:01 cdt eth1 110.65 121.85 18.14 107.13 0.00 0.00 0.00
12:30:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:30:01 cdt eth0 147.85 132.49 115.78 20.45 0.00 0.00 0.00
12:30:01 cdt eth1 111.88 127.39 18.61 117.65 0.00 0.00 0.00
12:40:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:40:01 cdt eth0 136.75 124.64 105.24 19.48 0.00 0.00 0.00
12:40:01 cdt eth1 101.65 115.32 17.58 104.50 0.00 0.00 0.00
12:50:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:50:01 cdt eth0 131.45 125.69 96.49 19.58 0.00 0.00 0.00
12:50:01 cdt eth1 101.41 111.31 17.54 96.78 0.00 0.00 0.00
01:00:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:00:01 cdt eth0 140.30 133.27 102.17 20.75 0.00 0.00 0.00
01:00:01 cdt eth1 106.90 119.51 18.53 103.09 0.00 0.00 0.00
01:10:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:10:01 cdt eth0 152.03 127.74 125.56 19.85 0.00 0.00 0.00
01:10:01 cdt eth1 115.60 134.57 18.73 126.96 0.00 0.00 0.00
01:20:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:20:01 cdt eth0 138.55 130.55 103.03 20.20 0.00 0.00 0.00
....
..
....
..
.
01:00:01 cdt eth1 156.82 169.48 28.83 138.49 0.00 0.00 0.00
01:10:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:10:01 cdt eth0 215.19 194.82 163.11 30.99 0.00 0.00 0.00
01:10:01 cdt eth1 162.49 183.79 28.36 163.70 0.00 0.00 0.00
01:20:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:20:01 cdt eth0 200.20 192.23 140.64 30.93 0.00 0.00 0.00
01:20:01 cdt eth1 153.60 166.96 27.32 140.26 0.00 0.00 0.00
01:30:01 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:30:01 cdt eth0 111.98 103.58 79.12 16.52 0.00 0.00 0.48
01:30:01 cdt eth1 87.50 95.58 14.74 79.35 0.00 0.00 0.00
average: iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
average: eth0 211.21 196.20 156.18 31.20 0.00 0.00 0.01
average: eth1 159.10 174.52 28.00 149.95 0.00 0.00 0.00
或者输入以下命令:
输出样例:
linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) tuesday 13 march 2012 _x86_64_ (2 cpu)
01:44:03 cdt iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
01:44:04 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:04 cdt eth0 161.70 154.26 105.20 26.63 0.00 0.00 0.00
01:44:04 cdt eth1 145.74 142.55 25.11 144.94 0.00 0.00 0.00
01:44:04 cdt iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
01:44:05 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:05 cdt eth0 162.14 156.31 107.46 42.18 0.00 0.00 0.00
01:44:05 cdt eth1 135.92 138.83 39.38 104.92 0.00 0.00 0.00
01:44:05 cdt iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
01:44:06 cdt lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:06 cdt eth0 303.92 293.14 272.91 37.40 0.00 0.00 0.00
01:44:06 cdt eth1 252.94 290.20 34.87 263.50 0.00 0.00 0.00
average: iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
average: eth0 210.37 202.34 163.19 35.66 0.00 0.00 0.00
average: eth1 178.93 191.64 33.36 171.60 0.00 0.00 0.00