traceroute是用来跟踪数据包到达网络主机所经过的路由工具。在Linux系统中,称之为traceroute,在Windows中称为tracert。

一条路径上的每个设备traceroute要测3次。输出结果中包含每次测试的时间(ms)和设备的名称及其IP。

1、命令格式:traceroute [参数] [主机]

2、常用命令参数:

-n  直接使用IP地址而非主机名称

-m 设置数据包的最大存活数TTL的大小

-p  设置UDP传输协议的通信端口

-q  设置探测包的个数

3、使用实例

    命令:traceroute www.baidu.com

 [root@CentOS- shu]# traceroute www.baidu.com
traceroute to www.baidu.com (14.215.177.39), hops max, byte packets
10.18.242.125 (10.18.242.125) 4.081 ms 3.981 ms 4.666 ms
192.168.253.22 (192.168.253.22) 3.174 ms 3.788 ms 3.738 ms
192.168.253.5 (192.168.253.5) 27.642 ms 27.620 ms 27.581 ms
* * *

      命令:traceroute -m 10 www.baidu.com       跳数设置

 [root@CentOS- shu]# traceroute -m  www.baidu.com
traceroute to www.baidu.com (14.215.177.39), hops max, byte packets
10.18.242.125 (10.18.242.125) 6.263 ms 6.133 ms 6.187 ms
192.168.253.22 (192.168.253.22) 3.555 ms 3.454 ms 4.203 ms
192.168.253.5 (192.168.253.5) 22.571 ms 23.238 ms 23.737 ms
* * *
* * *
* * *
* * *
* * *
* * *
* * *
[root@CentOS- shu]#

命令:traceroute -n 132.121.86.3  显示IP地址,不查主机名

 [opan@op1 ~]$ sudo ssh 132.121.88.181
[root@nagios ~]# traceroute -n 132.121.86.3
traceroute to 132.121.86.3 (132.121.86.3), hops max, byte packets
132.121.88.254 14.634 ms 14.056 ms 13.639 ms
* * *
* * *
* * *

命令:traceroute -p 6888 www.baidu.com 探测包使用基本UDP端口设置6888

 [root@CentOS- shu]# traceroute -p  www.baidu.com
traceroute to www.baidu.com (14.215.177.39), hops max, byte packets
10.18.242.125 (10.18.242.125) 6.660 ms 7.026 ms 7.904 ms
192.168.253.22 (192.168.253.22) 3.838 ms 3.789 ms 3.735 ms
192.168.253.5 (192.168.253.5) 2.282 ms 2.915 ms 3.570 ms
* * *

命令:traceroute -q 4 www.baidu.com  探测包的个数设置为4

 [root@CentOS- shu]# traceroute -q  www.baidu.com
traceroute to www.baidu.com (14.215.177.39), hops max, byte packets
10.18.242.125 (10.18.242.125) 5.458 ms 6.021 ms 7.104 ms 7.015 ms
192.168.253.22 (192.168.253.22) 4.377 ms 4.332 ms 4.272 ms 4.202 ms
192.168.253.5 (192.168.253.5) 2.150 ms 2.100 ms 2.043 ms 2.527 ms
* * * *

windows之tracert:

 C:\Users\Administrator>tracert www..com

 Tracing route to www..com [221.187.111.30]
over a maximum of hops: ms ms ms 10.58.156.1
ms < ms < ms 10.10.10.1
ms ms ms 211.103.193.129
ms ms ms 10.255.109.129
ms ms ms 124.205.98.205
ms ms ms 124.205.98.253
ms ms ms 202.99.1.125
ms ms ms 118.186.0.113
ms * * 118.186.0.106
ms ms ms 124.238.226.201
ms ms ms 219.148.19.177
ms ms ms 219.148.18.117
ms ms ms 219.148.19.125
ms ms ms 202.97.80.113
* * * Request timed out.
ms ms ms bj141--.bjtelecom.net [219.141.147.82]
ms ms ms 202.97.48.2
* * * Request timed out.
ms ms ms 221.187.224.85
ms ms ms 221.187.104.2
* * * Request timed out.
ms ms ms 221.187.111.30 Trace complete.
05-11 16:01