网络故障排查命令

查看网关

1
2
3
4
5
6
7
8
[root@luffy ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.67.9.253 0.0.0.0 UG 100 0 0 ens192
10.67.8.0 0.0.0.0 255.255.252.0 U 100 0 0 ens192
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-c941541f478c
192.0.2.128 0.0.0.0 255.255.255.128 U 0 0 0 br-69a5ef1e769f

ping

1
2
3
4
5
6
7
8
9
10
[root@luffy ~]# ping 10.67.44.117
PING 10.67.44.117 (10.67.44.117) 56(84) bytes of data.
64 bytes from 10.67.44.117: icmp_seq=2 ttl=63 time=0.377 ms
64 bytes from 10.67.44.117: icmp_seq=3 ttl=63 time=0.372 ms
64 bytes from 10.67.44.117: icmp_seq=4 ttl=63 time=0.386 ms
64 bytes from 10.67.44.117: icmp_seq=5 ttl=63 time=0.361 ms
^C
--- 10.67.44.117 ping statistics ---
5 packets transmitted, 4 received, 20% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.361/0.374/0.386/0.009 ms

traceroute 追踪路由

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
[root@luffy ~]# traceroute -w 1 baidu.com
traceroute to baidu.com (39.156.66.10), 30 hops max, 60 byte packets
1 gateway (10.67.9.253) 3.301 ms 3.596 ms 3.854 ms
2 10.67.254.254 (10.67.254.254) 0.175 ms 0.169 ms 0.156 ms
3 111.46.57.1 (111.46.57.1) 2.739 ms 2.786 ms 2.778 ms
4 120.202.252.181 (120.202.252.181) 3.145 ms 3.306 ms 120.202.2.13 (120.202.2.13) 1.148 ms
5 221.183.74.165 (221.183.74.165) 4.410 ms 3.952 ms 3.946 ms
6 221.183.37.225 (221.183.37.225) 19.831 ms 221.183.37.141 (221.183.37.141) 25.085 ms 221.183.37.225 (221.183.37.225) 19.781 ms
7 * 221.183.49.122 (221.183.49.122) 25.900 ms 24.989 ms
8 * 111.13.188.38 (111.13.188.38) 22.599 ms 20.465 ms
9 39.156.67.1 (39.156.67.1) 21.634 ms 21.592 ms 39.156.27.5 (39.156.27.5) 24.155 ms
10 * 39.156.67.17 (39.156.67.17) 28.742 ms 28.675 ms
11 * * * # 不支持用traceroute 查看,会以* 展示
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *

mtr

1
2
3
4
5
6
My traceroute  [v0.85]
luffy.super (::) Sun Jun 18 14:18:46 2023
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. localhost 0.0% 41 0.1 0.0 0.0 0.1 0.0

nsloopup 域名解析成ip

没有这个命令需要下载 bind-utils

1
2
3
4
5
6
7
8
9
[root@luffy ~]# nslookup baidu.com
Server: 223.5.5.5 # 通过这个域名服务器进行域名解析的
Address: 223.5.5.5#53

Non-authoritative answer:
Name: baidu.com
Address: 39.156.66.10 # 解析出的ip
Name: baidu.com
Address: 110.242.68.66

telnet 查看与主机的端口是否畅通

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@luffy ~]# telnet baidu.com 443
Trying 39.156.66.10...
Connected to baidu.com.
Escape character is '^]'.
^]
HTTP/1.1 302 Moved Temporarily
Server: bfe/1.0.8.18
Date: Sun, 18 Jun 2023 06:23:51 GMT
Content-Type: text/html
Content-Length: 161
Connection: close
Location: http://www.baidu.com/error.html

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>bfe/1.0.8.18</center>
</body>
</html>
Connection closed by foreign host.

tcpdump 抓包工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@luffy ~]# tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on docker0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[root@luffy ~]# tcpdump -i any -n port 80
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[root@luffy ~]# tcpdump -i any -n host 10.44.118
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[root@luffy ~]# tcpdump -i any -n host 10.44.118 and port 80 -w /temp/tcpdump.log2
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes

netstat 查看服务监听地址

-n 显示IP,不显示域名 -t tcp协议的 -p 进程 -l license

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@luffy ~]# netstat -ntpl
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:22 0.0.0.0:* LISTEN 1085/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1304/master
tcp6 0 0 :::8080 :::* LISTEN 1871/docker-proxy-c
tcp6 0 0 :::9009 :::* LISTEN 850/clickhouse-serv
tcp6 0 0 :::8081 :::* LISTEN 1884/docker-proxy-c
tcp6 0 0 :::22 :::* LISTEN 1085/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1304/master
tcp6 0 0 :::8123 :::* LISTEN 850/clickhouse-serv
tcp6 0 0 :::8000 :::* LISTEN 7394/docker-proxy-c
tcp6 0 0 :::9000 :::* LISTEN 850/clickhouse-serv
tcp6 0 0 :::9004 :::* LISTEN 850/clickhouse-serv
tcp6 0 0 :::9005 :::* LISTEN 850/clickhouse-serv

ss 和 netstat 类似

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
[root@luffy ~]# ss -ntpl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
users:(("sshd",pid=1085,fd=3))
LISTEN 0 100 127.0.0.1:25 *:*
users:(("master",pid=1304,fd=13))
LISTEN 0 128 [::]:8080 [::]:*
users:(("docker-proxy-cu",pid=1871,fd=4))
LISTEN 0 128 [::]:9009 [::]:*
users:(("clickhouse-serv",pid=850,fd=37))
LISTEN 0 128 [::]:8081 [::]:*
users:(("docker-proxy-cu",pid=1884,fd=4))
LISTEN 0 128 [::]:22 [::]:*
users:(("sshd",pid=1085,fd=4))
LISTEN 0 100 [::1]:25 [::]:*
users:(("master",pid=1304,fd=14))
LISTEN 0 128 [::]:8123 [::]:*
users:(("clickhouse-serv",pid=850,fd=35))
LISTEN 0 128 [::]:8000 [::]:*
users:(("docker-proxy-cu",pid=7394,fd=4))
LISTEN 0 128 [::]:9000 [::]:*
users:(("clickhouse-serv",pid=850,fd=36))
LISTEN 0 128 [::]:9004 [::]:*
users:(("clickhouse-serv",pid=850,fd=38))
LISTEN 0 128 [::]:9005 [::]:*
users:(("clickhouse-serv",pid=850,fd=39))

网络故障排查命令
https://luffy997.github.io/2023/05/22/网络故障排查命令/
作者
Luffy997
发布于
2023年5月22日
许可协议