MTR 是一款强大的网络诊断工具,它集成了 traceroute 和 ping 的功能,并且会收集更多的信息,比如连接状态、可用性等等,在排查网络问题中,非常有用。

MTR的安装

在 Linux 下可以直接使用 yum 工具(以 CentOS 为例)进行安装

yum install mtr

在 Windows 下,建议安装 besttrace ,这款工具带了 MTR 的功能。

在 macOS 下,建议使用 brew 进行安装。

1、安装 brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、安装 MTR

brew install mtr

3、把程序文件复制到 /usr/local/bin 目录下

cd /usr/local/Cellar/mtr/0.92/sbin
cp mtr /usr/local/bin/
cp mtr-packet /usr/local/bin/

4、运行 MTR 需要管理员权限,所以在运行的时候会提示输入密码

sudo mtr www.baidu.com

理解 MTR 报告

 

第一列:HOST,显示IP地址或者主机名。

第二列:Loss%,这个结点的丢包率。

第三列:Snt,发送包的数量。

第四列:Last,最近一次的延时,单位是毫秒ms。

第五列:Avg,平均延时,单位是毫秒ms。

第六列:Best,最低延时,单位是毫秒ms。

第七列:Wrst,最高延时,单位是毫秒ms。

第八列:StDev,标准偏差。

MTR 报告,我们一般看两样东西:丢包率和延迟。从上图中可以看到,有很多跳显示为 ??? (超时),并且丢包率为100%。这可能是家用路由器或者运营商的路由器没有正确配置导致的,但是数据还是正常传递的,看最后跳,丢包率为 0%,说明数据包全部到达目标主机。

导致丢包率主要有三个原因:

1、运营商限制 ICMP 速率。一些运营商会设置优先级,ICMP 包的优先级比较低,可能会被小部分丢弃。

2、ICMP 包在返回过程中出现丢包。数据包正常到达目的地,由于走不同的返程路由,在返回过程中出现丢包。因此,在遇到问题时,最好在两个方向收集 MTR 报告。

3、其他的网络故障。

MTR 参数详解

用法:mtr [参数] hostname

-F, --filename FILE        read hostname(s) from a file
 -4                         use IPv4 only
 -6                         use IPv6 only
 -u, --udp                  use UDP instead of ICMP echo
 -T, --tcp                  use TCP instead of ICMP echo
 -a, --address ADDRESS      bind the outgoing socket to ADDRESS
 -f, --first-ttl NUMBER     set what TTL to start
 -m, --max-ttl NUMBER       maximum number of hops
 -U, --max-unknown NUMBER   maximum unknown host
 -P, --port PORT            target port number for TCP, SCTP, or UDP
 -L, --localport LOCALPORT  source port number for UDP
 -s, --psize PACKETSIZE     set the packet size used for probing
 -B, --bitpattern NUMBER    set bit pattern to use in payload
 -i, --interval SECONDS     ICMP echo request interval
 -G, --gracetime SECONDS    number of seconds to wait for responses
 -Q, --tos NUMBER           type of service field in IP header
 -e, --mpls                 display information from ICMP extensions
 -Z, --timeout SECONDS      seconds to keep probe sockets open
 -r, --report               output using report mode
 -w, --report-wide          output wide report
 -c, --report-cycles COUNT  set the number of pings sent
 -j, --json                 output json
 -x, --xml                  output xml
 -C, --csv                  output comma separated values
 -l, --raw                  output raw format
 -p, --split                split output
 -t, --curses               use curses terminal interface
     --displaymode MODE     select initial display mode
 -n, --no-dns               do not resove host names
 -b, --show-ips             show IP numbers and host names
 -o, --order FIELDS         select output fields
 -y, --ipinfo NUMBER        select IP information in output
 -z, --aslookup             display AS number
 -h, --help                 display this help and exit
 -v, --version              output version information and exit
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐