Linux常用命令-traceroute

命令

traceroute

描述

print the route packets trace to network host
路由追踪

用法

1
2
traceroute [OPTIONS] host
traceroute6 [options] host

选项

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Options:
-4 使用IPv4
-6 使用IPv6
-d, --debug 启用debug
-F, --dont-fragment 不要分割数据包
-f first_ttl, --first=first_ttl 指定第一个TTL值,默认为1
-g gate,..., --gateway=gate,... 通过指定的网关路由数据包(IPv4最多8个,IPv6最多127个)
-I, --icmp 发送ICMP ECHO数据包
-T, --tcp 发送TCP SYN数据包,默认端口为80
-i device, --interface=device 指定出接口
-m max_ttl, --max-hops=max_ttl 指定最大TTL值,即路由跳数,默认为30
-N squeries, --sim-queries=squeries
Set the number of probes to be tried
simultaneously (default is 16)
-n 显示IP地址而不显示主机名
-p port, --port=port 指定目标端口. It is either
initial udp port value for "default" method
(incremented by each probe, default is 33434), or
initial seq for "icmp" (incremented as well,
default from 1), or some constant destination
port for other methods (with default of 80 for
"tcp", 53 for "udp", etc.)
-t tos, --tos=tos Set the TOS (IPv4 type of service) or TC (IPv6
traffic class) value for outgoing packets
-l flow_label, --flowlabel=flow_label
Use specified flow_label for IPv6 packets
-w waittime, --wait=waittime 指定等待响应的时间,默认为5s,支持浮点数,如9.5
-q nqueries, --queries=nqueries 指定每一跳的请求数量,默认为3
-r 绕过正常路由,直接发送到连接网络上的主机
-s src_addr, --source=src_addr 指定出接口的IP地址
-z sendwait, --sendwait=sendwait 探测之间的最小时间间隔,默认为0,单位秒,如果该值大于10,则单位为毫秒milliseconds
-e, --extensions Show ICMP extensions (if present), including MPLS
-A, --as-path-lookups 按照AS路径查找并显示
-M name, --module=name Use specified module (either builtin or external)
for traceroute operations. Most methods have
their shortcuts (`-I' means `-M icmp' etc.)
-O OPTS,..., --options=OPTS,...
Use module-specific option OPTS for the
traceroute module. Several OPTS allowed,
separated by comma. If OPTS is "help", print info
about available options
--sport=num Use source port num for outgoing packets. Implies
`-N 1'
--fwmark=num Set firewall mark for outgoing packets
-U, --udp 发送UDP数据包,默认端口53,配合-p选项指定端口
-UL Use UDPLITE for tracerouting (default dest port
is 53)
-D, --dccp Use DCCP Request for tracerouting (default port
is 33434)
-P prot, --protocol=prot Use raw packet of protocol prot for tracerouting
--mtu Discover MTU along the path being traced. Implies
`-F -N 1'
--back Guess the number of hops in the backward path and
print if it differs

Arguments:
+ host The host to traceroute to
packetlen The full packet length (default is the length of an IP
header plus 40). Can be ignored or increased to a minimal
allowed value

注意

Linux需要安装traceroute软件包,Windows系统自带的命令是tracert

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ traceroute -V
Modern traceroute for Linux, version 2.0.22

# -n 显示IP地址而不显示主机名
$ traceroute -n www.baidu.com
traceroute to www.baidu.com (110.242.68.3), 30 hops max, 60 byte packets
1 192.168.x.1 0.710 ms 0.690 ms 0.544 ms
2 1xx.2xx.1x.1 5.188 ms 4.938 ms 4.767 ms
3 1xx.1xx.2x.1x 5.395 ms 1xx.1xx.2x.1 8.531 ms 1x.1x.2xx.1x 7.512 ms
4 * * *
...
# 如上显示的结果说明,序列号从1开始,每个纪录就是一跳,表示一个网关,显示网关IP地址
# 每行显示有3个时间,单位是ms,其实就是-q的默认参数,
# 探测数据包向每个网关发送三个数据包,网关响应后显示返回的时间.如果指定-q 5则会显示5个时间
# 如果显示为星号*,可能是网关响应被防火墙禁止
# 如果某一台网关响应时间很长,则可能该网关设备出现拥堵,可联系IDC进一步查询

# -T -p 443 指定TCP的443端口
$ traceroute -Tn -p 443 www.baidu.com