Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_linux

0 前言

网络信息是电脑网络信息安全检查中的一块重要内容,Linux和基于Linux的操作系统,提供了很多的网络命令,今天我们研究tracepath命令。

Tracepath 在大多数 Linux 发行版中都是可用的。如果在你的系统中没有预装,请根据你的发行版使用下面的命令进行安装。

Windows中没有tracepath命令。

1 tracepath命令 的功能、格式和选项说明

1.1 tracepath命令 的功能

tracepath命令的功能是追踪数据包的路由信息,它可以追踪并显示数据包到达目的主机所经过的路由信息,以及对应的MTU值。

tracepath 与 traceroute 类似,用于确定数据包访问目的地所经历的路由路径。

Tracepath 特别适用于没有 root 权限的用户,因为它不需要特权即可运行。

1.2 tracepath命令 的格式

跟ping命令一样,我们可以使用 tracepath 或 tracepath -?命令获取ping命令的格式信息。 tracepath不支持 --?选项。

[purpleendurer @ bash ~] tracepath
Usage: tracepath [-n] [-b] [-l <len>] [-p port] <destination>
[purpleendurer @ bash ~] tracepath -?
Usage: tracepath [-n] [-b] [-l <len>] [-p port] <destination>
[purpleendurer @ bash ~] tracepath --?
tracepath: invalid option -- '-'
Usage: tracepath [-n] [-b] [-l <len>] [-p port] <destination>
[purpleendurer @ bash ~]
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_tracepath_02

 tracepath [-n] [-b] [-l <最大路径长度>] [-p 端口号] <目标域名或IP地址>

1.3 tracepath命令选项说明 

与ping命令相比,tracepath的命令不算多。

不过不同版本的Linux提供的tracepath命令选项不尽相同。 

选项

说明

-n

输出数字格式的地址

-b

输出回程路径

-l  最大路径长度

设置最大路径长度

-m 最大TTL值

设置查询的最大TTL值

-p 端口号

设置UDP端口号

-V

显示版本信息

2  tracepath命令实例

2.1 tracepath g.cn

[purpleendurer @ bash ~] tracepath g.cn
 1?: [LOCALHOST]                                         pmtu 1500
 1:  26.10.178.42                                          2.037ms 
 1:  26.10.178.42                                          2.238ms 
 2:  11.73.57.238                                          1.986ms 
 3:  11.73.37.65                                           1.852ms 
 4:  11.73.49.81                                           3.004ms 
 5:  10.222.215.161                                        2.377ms 
 6:  10.54.171.129                                         3.831ms 
 7:  10.102.154.246                                        4.610ms asymm  6 
 8:  no reply
 9:  no reply
10:  61.149.190.38                                         5.299ms asymm  9 
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 
[purpleendurer @ bash ~]
  • 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.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_linux_03

命令返回信息中的PMTU  (Path Maximum Transmission Unit,数据通信网络中发现路径最大传输单元)是优化网络性能的关键技术之一。PMTU决定了数据在网络中传输的最大数据包大小 。

2.2  tracepath -b g.cn :输出回程路径

[purpleendurer @ bash ~] tracepath -b g.cn
 1?: [LOCALHOST]                                         pmtu 1500
 1:  26.10.178.42 (26.10.178.42)                           2.308ms 
 2:  11.73.56.206 (11.73.56.206)                           1.952ms 
 3:  11.73.31.193 (11.73.31.193)                           2.034ms 
 4:  11.73.48.73 (11.73.48.73)                             2.678ms 
 5:  10.222.214.217 (10.222.214.217)                      15.309ms 
 6:  10.54.171.141 (10.54.171.141)                         3.707ms 
 7:  10.102.154.222 (10.102.154.222)                       4.003ms 
 8:  no reply
 9:  no reply
10:  114.243.132.194 (114.243.132.194)                     5.394ms asymm  9 
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 
[purpleendurer @ bash ~]
  • 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.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_tracepath_04

2.3 tracepath -l 512 g.cn:设置最大路径长度为512

[purpleendurer @ bash ~] tracepath -l 512 g.cn
 1:  26.10.178.42                                          2.625ms 
 2:  11.73.56.206                                          1.956ms 
 3:  11.73.37.161                                          1.943ms 
 4:  11.73.50.209                                          3.318ms 
 5:  10.222.214.241                                        3.257ms 
 6:  11.94.197.101                                         3.779ms asymm  7 
 7:  116.251.112.161                                       4.019ms asymm  6 
 8:  no reply
 9:  no reply
10:  114.243.132.194                                       5.299ms asymm  9 
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 512
     Resume: pmtu 512 
[purpleendurer @ bash ~]
  • 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.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_网络管理_05

 2.4 tracepath -p 80 g.cn:使用UDP 80端口

[purpleendurer @ bash ~] tracepath -p 80 g.cn
 1?: [LOCALHOST]                                         pmtu 1500
 1:  26.10.178.42                                          2.337ms 
 1:  26.10.178.42                                          2.357ms 
 2:  11.73.56.78                                           1.909ms 
 3:  11.73.36.129                                          1.877ms 
 4:  11.73.43.185                                          2.385ms 
 5:  10.222.214.193                                        2.221ms 
 6:  10.54.171.221                                         3.892ms 
 7:  116.251.112.157                                       3.971ms asymm  6 
 8:  no reply
 9:  125.33.184.177                                        4.492ms asymm  8 
10:  114.243.132.194                                       4.819ms asymm  9 
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 
[purpleendurer @ bash ~]
  • 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.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_学习笔记_06

2.5 tracepath -n g.cn :输出数字格式的地址

[purpleendurer @ bash ~] tracepath -n g.cn
 1?: [LOCALHOST]                                         pmtu 1500
 1:  26.10.178.42                                          2.073ms 
 1:  26.10.178.42                                          2.068ms 
 2:  11.73.57.174                                          1.826ms 
 3:  11.73.32.57                                           2.603ms 
 4:  11.73.52.81                                           2.285ms 
 5:  10.222.215.113                                        2.359ms 
 6:  10.54.171.141                                         3.860ms 
 7:  10.102.154.234                                        3.791ms 
 8:  no reply
 9:  no reply
10:  114.243.132.194                                       4.967ms asymm  9 
11:  no reply
12:  no reply
13:  no reply
14:  no reply
15:  no reply
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 
[purpleendurer @ bash ~]
  • 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.

Linux shell编程学习笔记67: tracepath命令 追踪数据包的路由信息_学习笔记_07