Linux常用命令-mtr

命令

mtr

描述

a network diagnostic tool
网络诊断工具

用法

1
mtr [OPTIONS] HOSTNAME

选项

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
Options:
-4 使用IPv4
-6 使用IPv6
-r,--report 启用repot模式,即直接显示统计信息而非交互式,通常配合-c选项一起使用
-w,--report-wide 启用wide report模式,即不会自动裁减显示主机名,适用于主机名较长的情况
-c,--report-cycles 指定发送的ping请求的数量
-s,--psize 指定发送的数据包的大小,单位字节bytes,包括IP和ICMP头部
-n,--no-dns 显示IP地址而不显示主机名
-b,--show-ips 同时显示主机名和IP地址
-o,--order 显示指定的列表字段,可选字段说明如下,例如-o "LSD NBAW"
-p,--split 显示简洁格式,空格分隔
-l,--raw 显示原始格式
-x,--xml 显示xml格式
-a,--address 指定出接口的IP地址
-i,--interval 指定ICMP ECHO requests请求的时间间隔,默认为1s
-m,--max-ttl 指定TTL值,即跟踪路由的最大跳数,默认为30
-f,--first-ttl 指定初始的TTL值,默认为1
-Q,--tos 指定ToS字段的值,取值范围0-255
-u,--udp 使用UDP数据包而不是ICMP ECHO
-T,--tcp 使用TCP SYN数据包
-P,--port 指定TCP跟踪的目标端口号
--timeout 指定超时时间

-o 可选字段列表说明
┌──┬─────────────────────┐
│L │ Loss ratio │
├──┼─────────────────────┤
│D │ Dropped packets │
├──┼─────────────────────┤
│R │ Received packets │
├──┼─────────────────────┤
│S │ Sent Packets │
├──┼─────────────────────┤
│N │ Newest RTT(ms) │
├──┼─────────────────────┤
│B │ Min/Best RTT(ms) │
├──┼─────────────────────┤
│A │ Average RTT(ms) │
├──┼─────────────────────┤
│W │ Max/Worst RTT(ms) │
├──┼─────────────────────┤
│V │ Standard Deviation │
├──┼─────────────────────┤
│G │ Geometric Mean │
├──┼─────────────────────┤
│J │ Current Jitter │
├──┼─────────────────────┤
│M │ Jitter Mean/Avg. │
├──┼─────────────────────┤
│X │ Worst Jitter │
├──┼─────────────────────┤
│I │ Interarrival Jitter │
└──┴─────────────────────┘

# mtr支持的交互式命令
$ mtr -n www.baidu.com
Command:
?|h help
p pause (SPACE to resume)
d switching display mode
e toggle MPLS information on/off
n toggle DNS on/off
r reset all counters
o str set the columns to display, default str='LRS N BAWV'
j toggle latency(LS NABWV)/jitter(DR AGJMXI) stats
c <n> report cycle n, default n=infinite
i <n> set the ping interval to n seconds, default n=1
f <n> set the initial time-to-live(ttl), default n=1
m <n> set the max time-to-live, default n= # of hops
s <n> set the packet size to n or random(n<0)
b <c> set ping bit pattern to c(0..255) or random(c<0)
Q <t> set ping packet's TOS to t
u switch between ICMP ECHO and UDP datagrams
y switching IP info
z toggle ASN info on/off
press any key to go back...

注意

mtr命令需要安装mtr软件包,测试网络质量时会产生大量的网络流量,可能会导致网络性能下降

示例

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
$ mtr -v
mtr 0.85

# 默认显示为交互式,h键帮助,q键退出
$ mtr www.baidu.com
My traceroute [v0.85]
Keys: Help Display mode Restart statistics Order of fields quit
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. 192.168.xx.1 0.0% 31 0.9 1.0 0.9 1.3 0.0
2. 1xx.2xx.1xx.1 0.0% 31 3.4 18.2 2.3 96.0 23.4
3. 1xx.1x.2xx.2x 0.0% 31 6.1 6.8 2.6 21.0 4.5
4. 1xx.3x.1x.2xx 60.0% 31 3.2 3.9 3.2 6.4 0.6
5. xx1.1x.2xx.1xx 32.3% 31 4.9 4.5 4.0 5.9 0.2
6. 2xx.1xx.9.2xx 86.7% 31 7.3 8.8 6.9 13.9 3.4
7. xx2.2xx.6x.1xx 0.0% 31 10.5 10.5 9.7 13.9 0.6
8. 2xx.1xx.4x.1xx 0.0% 31 10.4 12.9 9.7 34.5 5.4
9. ???
10. ???
11. ???
12. 110.242.68.3 0.0% 30 9.9 11.0 9.7 18.6 2.0
$ ping www.baidu.com
PING www.baidu.com (110.242.68.3) 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=53 time=11.7 ms
# 如上mtr结果有3台中间节点出现丢包,可能是配置了ICMP限速导致,在后续节点和目标节点上没有丢包,则可以忽略中间节点的影响

mtr默认返回的结果说明
第一列(Host):节点IP地址和域名。按n键可切换显示。
第二列(Loss%):节点丢包率。
第三列(Snt):每秒发送数据包数。默认值是10,可以通过-c参数指定。
第四列(Last):最近一次的探测延迟。
第五、六、七列(Avg、Best、Worst):分别是探测延迟的平均值、最小值和最大值。
第八列(StDev):标准偏差,越大说明相应节点越不稳定。

# 目标主机不可达
$ mtr www.google.com
Host Loss% Snt Last Avg Best Wrst StDev
1. 192.168.xx.1 0.0% 30 1.1 1.0 0.9 1.2 0.0
2. 1xx.2xx.1xx.1 0.0% 30 3.1 6.0 2.2 74.1 13.1
3. 1xx.1xx.2x.1x 0.0% 30 4.5 4.3 2.3 6.7 1.1
4. 1xx.3x.5x.4x 43.3% 30 4.3 5.3 3.2 13.9 2.9
5. 1xx.3x.1xx.1xx 86.2% 30 3.5 4.0 3.5 4.7 0.0
6. 2xx.1xx.1xx.2xx 93.1% 30 42.6 41.6 40.5 42.6 1.4
7. ???
$ ping www.google.com
PING www.google.com (142.250.196.100) 56(84) bytes of data.

# -c 指定发送的数据包数量, -r 显示统计信息
$ mtr -r -c 3 www.baidu.com
# -n 显示IP地址
$ mtr -rn -c 1 www.baidu.com
# -b 同时显示主机名和IP地址
$ mtr -rb -c 1 www.baidu.com
# -p 显示简洁模式
$ mtr -p www.baidu.com
1 192.168.xx.1 0 1 1 1 1 1
2 1xx.2xx.1xx.1 0 1 1 3 3 3
3 1xx.1xx.2x.2x 0 1 1 6 6 6
...