Linux mtr 命令详解

ㄒiger / Posted in 程序代码 / January 9, 2012

一般在windows 来判断网络连通性用ping 和tracert,ping的话可以来判断丢包率,tracert可以用来跟踪路由,在Linux中有一个更好的网络连通性判断工具,它可以结合ping nslookup tracert 来判断网络的相关特性,这个命令就是mtr

centos下面如果没安装就先 yum install mtr


[root@dns ~]# mtr -h
-bash: mtr: command not found
[root@dns ~]#
[root@dns ~]# yum install mtr
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.usc.edu
* extras: mirrors.easynews.com
* updates: mirrors.easynews.com
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
updates/primary_db | 433 kB 00:00
vz-base | 951 B 00:00
vz-updates | 951 B 00:00
Excluding Packages in globalexclude list
Finished
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mtr.i386 2:0.71-3.1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mtr i386 2:0.71-3.1 base 50 k
Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 50 k
Is this ok [y/N]: y
Downloading Packages:
mtr-0.71-3.1.i386.rpm | 50 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mtr 1/1
Installed:
mtr.i386 2:0.71-3.1
Complete!

mtr -h提供帮助命令
mtr -v显示mtr的版本信息
mtr -r已报告模式显示



[root@dns ~]# mtr -r 8.8.8.8
dns.tiger.im Snt: 10 Loss% Last Avg Best Wrst StDev
173.232.0.14 0.0% 0.1 0.1 0.1 0.1 0.0
phx1.200-1.5.bb2.po11.gi3-1-9.eonixco.v4.inf 0.0% 0.3 1.0 0.3 3.7 1.4
gige-g1-6.core1.phx2.he.net 0.0% 0.6 0.6 0.4 1.1 0.2
10gigabitethernet1-4.core1.phx1.he.net 0.0% 6.7 3.1 0.8 9.5 2.9
10gigabitethernet2-2.core1.lax1.he.net 0.0% 12.1 13.7 11.1 20.9 3.0
core1-0-1-0.lax.net.google.com 0.0% 27.8 16.9 11.2 45.0 11.1
72.14.234.47 0.0% 12.0 21.0 11.5 101.3 28.2
64.233.174.190 0.0% 14.0 20.1 11.5 41.2 12.6
72.14.239.162 0.0% 40.5 41.6 40.4 47.0 1.9
216.239.48.165 10.0% 41.0 41.2 40.2 43.6 1.1
72.14.232.2 80.0% 53.8 50.2 46.7 53.8 5.0
google-public-dns-a.google.com 0.0% 40.5 40.9 40.3 42.0 0.6

第一列:显示的是IP地址和本机域名,这点和tracert很像
第二列:snt:10 设置每秒发送数据包的数量,默认值是10 可以通过参数 -c来指定。


[root@dns ~]# mtr -r -c 15 8.8.8.8
dns.tiger.im Snt: 15 Loss% Last Avg Best Wrst StDev
173.232.0.14 0.0% 0.1 0.1 0.1 0.1 0.0
phx1.200-1.5.bb2.po11.gi3-1-9.eonixco.v4.inf 0.0% 4.0 0.9 0.3 4.1 1.3
gige-g1-6.core1.phx2.he.net 0.0% 0.9 1.4 0.3 7.7 1.9
10gigabitethernet1-4.core1.phx1.he.net 0.0% 7.0 3.2 0.8 10.8 3.2
10gigabitethernet2-2.core1.lax1.he.net 0.0% 11.3 12.4 11.2 18.8 2.2
core1-0-1-0.lax.net.google.com 0.0% 12.7 16.6 11.1 57.9 13.3
72.14.234.47 0.0% 11.7 16.6 11.4 81.0 17.8
64.233.174.186 0.0% 12.2 29.2 11.5 57.0 16.6
72.14.239.162 0.0% 41.0 43.2 40.4 57.0 5.1
216.239.48.165 0.0% 41.0 42.1 40.2 58.2 4.6
72.14.232.2 60.0% 49.0 45.1 40.8 50.5 4.0
google-public-dns-a.google.com 0.0% 40.4 41.2 40.3 43.9 1.0

其中-c的说明是:–report-cycles COUNT
第三列:是显示的每个对应IP的丢包率
第四列:显示的最近一次的返回时延
第五列:是平均值 这个应该是发送ping包的平均时延
第六列:是最好或者说时延最短的
第七列:是最差或者说时延最常的
第八列:是标准偏差
接下来接着说相关参数:

mtr -s用来指定ping数据包的大小
mtr -nno-dns不对IP地址做域名解析
mtr -a来设置发送数据包的IP地址 这个对一个主机由多个IP地址是有用的
mtr -i使用这个参数来设置ICMP返回之间的要求默认是1秒
mtr -4IPv4
mtr -6IPv6
 来源:http://blog.51bbo.com/archives/241

其他相关文章....