部分网络命令

设置 ip 地址

1
2
ifconfig eth0 192.168.1.10
ifconfig eth0 192.168.1.10 netmask 255.255.255.0

参数解释

比如 查看 网卡 eth0

1
2
3
4
5
6
7
8
9
10
[root@imwl-175 ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 66.42.99.175 netmask 255.255.254.0 broadcast 66.42.99.255
inet6 fe80::5400:3ff:fe45:3c73 prefixlen 64 scopeid 0x20<link>
inet6 2001:19f0:6001:4b30:5400:3ff:fe45:3c73 prefixlen 64 scopeid 0x0<global>
ether 56:00:03:45:3c:73 txqueuelen 1000 (Ethernet)
RX packets 3193275 bytes 2157200207 (2.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3225664 bytes 2355880326 (2.1 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  1. RUNNING : 表示网络是连通的
  2. MTU : 默认为 1500
  3. TX : 发送
  4. RX : 接受
  5. errors : 错误的数据包数,eg: 校验错误,帧同步错误
  6. dropped : 丢弃的数据包数,数据包已经到了 ring buffer, 但因为内存不足等原因丢包
  7. overruns : 超限数据包, 网络 IO 过快,导致 ring buffer 中的数据包来不及处理(队列满)而导致的丢包
  8. carrier : 一般是双工不匹配,物理电缆出现问题
  9. collisions : 碰撞数据包数

ss 与 netstat 查看套接字信息

-l : 监听套接字
-n : 显示数字地址和端口
-p : 显示 进程信息
-t : 显示 tcp 套接字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@imwl-175 ~]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 537/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 919/nginx: master p
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 909/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1038/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 906/trojan
tcp6 0 0 :::111 :::* LISTEN 537/rpcbind
tcp6 0 0 :::8080 :::* LISTEN 4307/docker-proxy-c
tcp6 0 0 :::22 :::* LISTEN 909/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1038/master
tcp6 0 0 :::2377 :::* LISTEN 3586/dockerd-curren
tcp6 0 0 :::7946 :::* LISTEN 3586/dockerd-curren
udp 0 0 0.0.0.0:68 0.0.0.0:* 846/dhclient
udp 0 0 0.0.0.0:111 0.0.0.0:* 537/rpcbind
udp 0 0 127.0.0.1:323 0.0.0.0:* 590/chronyd
udp 0 0 0.0.0.0:4789 0.0.0.0:* -
udp 0 0 0.0.0.0:700 0.0.0.0:* 537/rpcbind
udp6 0 0 :::7946 :::* 3586/dockerd-curren
udp6 0 0 :::111 :::* 537/rpcbind
udp6 0 0 ::1:323 :::* 590/chronyd
udp6 0 0 :::700 :::* 537/rpcbind

Recv-Q : 接收队列
Send-Q : 发送队列

协议栈信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
[root@imwl-175 ~]# netstat -s
Ip:
3215047 total packets received
6537 forwarded
1 with unknown protocol
0 incoming packets discarded
3208496 incoming packets delivered
3295252 requests sent out
7 outgoing packets dropped
Icmp:
1434 ICMP messages received
48 input ICMP message failed.
ICMP input histogram:
destination unreachable: 472
timeout in transit: 11
echo requests: 947
echo replies: 4
3204 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 2257
echo replies: 947
IcmpMsg:
InType0: 4
InType3: 472
InType8: 947
InType11: 11
OutType0: 947
OutType3: 2257
Tcp:
28888 active connections openings
102936 passive connection openings
3978 failed connection attempts
2579 connection resets received
7 connections established
3006869 segments received
3442563 segments send out
287671 segments retransmited
42693 bad segments received.
54447 resets sent
InCsumErrors: 42679
Udp:
342293 packets received
2261 packets to unknown port received.
0 packet receive errors
340842 packets sent
0 receive buffer errors
0 send buffer errors
UdpLite:
TcpExt:
859 resets received for embryonic SYN_RECV sockets
79 packets pruned from receive queue because of socket buffer overrun
1 ICMP packets dropped because they were out-of-window
23297 TCP sockets finished time wait in fast timer
168067 delayed acks sent
12 delayed acks further delayed because of locked socket
Quick ack mode was activated 23425 times
2 SYNs to LISTEN sockets dropped
506703 packet headers predicted
1088634 acknowledgments not containing data payload received
510495 predicted acknowledgments
23673 times recovered from packet loss by selective acknowledgements
Detected reordering 13094 times using SACK
Detected reordering 29 times using reno fast retransmit
2 congestion windows fully recovered without slow start
464 congestion windows recovered without slow start by DSACK
578 congestion windows recovered without slow start after partial ack
TCPLostRetransmit: 27128
242 timeouts after SACK recovery
250 timeouts in loss state
155981 fast retransmits
2415 retransmits in slow start
21238 other TCP timeouts
TCPLossProbes: 31134
TCPLossProbeRecovery: 4774
2579 SACK retransmits failed
23720 DSACKs sent for old packets
49 DSACKs sent for out of order packets
9217 DSACKs received
339 DSACKs for out of order packets received
1380 connections reset due to unexpected data
46 connections reset due to early user close
13845 connections aborted due to timeout
TCPDSACKIgnoredOld: 55
TCPDSACKIgnoredNoUndo: 5132
TCPSpuriousRTOs: 92
TCPSackShifted: 137476
TCPSackMerged: 343569
TCPSackShiftFallback: 165507
TCPRcvCoalesce: 244304
TCPOFOQueue: 18977
TCPOFOMerge: 49
TCPChallengeACK: 37
TCPSYNChallenge: 14
TCPFastOpenActive: 1681
TCPFastOpenActiveFail: 1445
TCPFastOpenCookieReqd: 848
TCPFastOpenBlackhole: 5
TCPSpuriousRtxHostQueues: 28
TCPAutoCorking: 20068
TCPFromZeroWindowAdv: 853
TCPToZeroWindowAdv: 855
TCPWantZeroWindowAdv: 657
TCPSynRetrans: 8587
TCPOrigDataSent: 2429980
TCPACKSkippedSynRecv: 16
TCPACKSkippedSeq: 642
TCPACKSkippedChallenge: 2
TCPWinProbe: 34
TCPKeepAlive: 626
TCPWqueueTooBig: 17
IpExt:
InNoRoutes: 13
InOctets: 1219007134
OutOctets: 2346546494
InNoECTPkts: 3217097
InECT1Pkts: 1
InECT0Pkts: 450
InCEPkts: 1801