功能概述
traceroute用于显示源主机到目标主机之间的网关信息。traceroute的实现原理是基于报文的TTL,可以通过TCP/UDP/ICMP等协议传输(默认是UDP协议)。
使用示例
- 示例一:traceroute google.com
$ traceroute google.com
traceroute to google.com (142.250.205.174), 30 hops max, 60 byte packets
1 _gateway (172.16.182.2) 0.317 ms 0.290 ms 0.382 ms
2 10.86.108.1 (10.86.108.1) 6.215 ms 6.092 ms 6.003 ms
3 10.86.96.1 (10.86.96.1) 5.928 ms 5.835 ms 5.760 ms
4 172.23.0.1 (172.23.0.1) 30.755 ms 30.683 ms 30.592 ms
5 10.246.40.23 (10.246.40.23) 106.663 ms 106.592 ms 106.500 ms
6 100.122.241.30 (100.122.241.30) 106.428 ms 104.708 ms 104.601 ms
7 * 100.124.112.23 (100.124.112.23) 103.999 ms 100.124.112.21 (100.124.112.21) 103.874 ms
8 100.124.113.40 (100.124.113.40) 108.972 ms 108.843 ms 100.124.112.58 (100.124.112.58) 108.647 ms
9 15169.sgw.equinix.com (27.111.228.150) 108.533 ms 108.509 ms 108.757 ms
10 108.170.240.225 (108.170.240.225) 108.277 ms 108.478 ms 108.392 ms
11 142.251.49.191 (142.251.49.191) 108.018 ms 108.170.240.161 (108.170.240.161) 107.933 ms 142.251.49.191 (142.251.49.191) 107.759 ms
12 sin10s31-in-f14.1e100.net (142.250.205.174) 109.795 ms 108.460 ms 142.251.52.49 (142.251.52.49) 111.422 ms
界面介绍:
- 每一行表示一跳,即一个网关。
- “30 hops max” 表示最大跳数限制。
- “60 byte packets” 表示传输包的大小。
- “_gateway (172.16.182.2)” 表示该网关的DNS名称和IP地址。
- “0.317 ms 0.290 ms 0.382 ms” 表示一共给该网关传输3个数据包,每个包的RTT。
- 示例二:
-q
控制发送数据包的数量为1
$ traceroute -q 1 google.com
traceroute to google.com (142.250.205.206), 30 hops max, 60 byte packets
1 _gateway (172.16.182.2) 0.301 ms
2 10.86.108.1 (10.86.108.1) 3.890 ms
3 10.86.96.1 (10.86.96.1) 4.105 ms
4 172.23.0.1 (172.23.0.1) 32.826 ms
5 10.246.40.23 (10.246.40.23) 107.003 ms
6 100.122.241.30 (100.122.241.30) 106.987 ms
7 100.124.112.23 (100.124.112.23) 106.707 ms
8 100.124.112.32 (100.124.112.32) 107.373 ms
9 172.17.4.50 (172.17.4.50) 106.493 ms
10 74.125.242.33 (74.125.242.33) 107.189 ms
11 *
12 sin11s28-in-f14.1e100.net (142.250.205.206) 107.010 ms
界面补充:
- 当主机名出现"*“表示该网关的防火墙屏蔽掉了ICMP的返回信息,因此无法正常显示主机名。
- 示例三:
-I
基于ICMP协议
$ traceroute -I google.com
traceroute to google.com (74.125.24.138), 30 hops max, 60 byte packets
1 _gateway (172.16.182.2) 0.159 ms 0.089 ms 0.143 ms
2 10.86.108.1 (10.86.108.1) 5.291 ms 5.262 ms 5.215 ms
3 10.86.96.1 (10.86.96.1) 2.400 ms 2.372 ms 2.341 ms
4 172.20.0.1 (172.20.0.1) 29.703 ms 29.675 ms 29.646 ms
5 10.246.40.23 (10.246.40.23) 102.332 ms 102.300 ms 102.272 ms
6 * 100.122.241.30 (100.122.241.30) 102.204 ms 102.125 ms
7 100.124.112.23 (100.124.112.23) 101.666 ms 101.742 ms 101.660 ms
8 100.124.112.38 (100.124.112.38) 101.705 ms 101.669 ms 101.613 ms
9 * * *
10 142.250.161.88 (142.250.161.88) 103.829 ms 103.778 ms 103.739 ms
11 108.170.240.225 (108.170.240.225) 104.616 ms 104.039 ms 105.102 ms
12 108.170.240.241 (108.170.240.241) 101.464 ms 101.431 ms 104.660 ms
13 * * *
14 209.85.243.180 (209.85.243.180) 104.347 ms 104.238 ms 104.224 ms
15 66.249.94.59 (66.249.94.59) 104.217 ms 104.211 ms 104.208 ms
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 74.125.24.138 (74.125.24.138) 107.518 ms 107.433 ms 120.414 ms
值得注意的是,公网上面的ICMP经常因为防火墙的原因被封禁,因此实用性不大。
- 示例四:
-T
基于TCP协议
$ traceroute -I google.com
traceroute to google.com (142.250.205.206), 30 hops max, 60 byte packets
1 _gateway (172.16.182.2) 0.190 ms 0.100 ms 0.083 ms
2 sin11s28-in-f14.1e100.net (142.250.205.206) 106.429 ms 107.844 ms 104.815 ms