路由跟踪

traceroute

打印用于跟踪到网络主机的路由包。利用了IP协议的存活时间(time to live, TTL)字段和尝试引起到目的主机路径的每个网关的 ICMP TIME_EXCEEDED 响应。

Traceroute的工作原理(来自:http://www.cnblogs.com/peida/archive/2013/03/07/2947326.html

Traceroute最简单的基本用法是:traceroute hostname
Traceroute 程序的设计是利用ICMP及IP header的TTL(Time To Live)栏位(field)。首先,traceroute送出一个TTL是1 的IP datagram(其实,每次送出的为3个40字节的包,包括源地址,目的地址和包发出的时间标签)到目的地,当路径上的第一个路由器 (router)收到这个datagram时,它将TTL减1。此时,TTL变为0了,所以该路由器会将此datagram丢掉,并送回一个 「ICMP time exceeded」消息(包括发IP包的源地址,IP包的所有内容及路由器的IP地址),traceroute 收到这个消息后, 便知道这个路由器存在于这个路径上,接着traceroute 再送出另一个TTL是2 的datagram,发现第2 个路由 器...... traceroute 每次将送出的datagram的TTL 加1来发现另一个路由器,这个重复的动作一直持续到某个 datagram 抵达目的地。当datagram到达目的地后,该主机并不会送回ICMP time exceeded消息,因为它已是目的地了,那么 traceroute如何得知目的地到达了呢?
Traceroute 在送出UDP datagrams到目的地时,它所选择送达的port number 是一个一般应用程序都不会用的号码(30000 以上),所以当此 UDP datagram 到达目的地后该主机会送回一个「ICMP port unreachable」的消息,而当traceroute 收到这个消 息时,便知道目的地已经到达了。所以traceroute 在Server端也是没有所谓的Daemon 程式。
Traceroute提取发 ICMP TTL到期消息设备的IP地址并作域名解析。每次 ,Traceroute都打印出一系列数据,包括所经过的路由设备的域名及 IP地址,三个包每次来回所花时间。
     

完整命令选项:

traceroute [-46dFITUnreAV] [-f first_ttl] [-g gate,...]
        [-i device] [-m max_ttl] [-p port] [-s src_addr]
        [-q nqueries] [-N squeries] [-t tos]
        [-l flow_label] [-w waittime] [-z sendwait]
        [-UL] [-P proto] [--sport=port] [-M method] [-O mod_options]
        [--mtu] [--back]
        host [packet_len]
traceroute6  [options]
tcptraceroute  [options]
lft  [options]

traceroute6 等价于 traceroute -6

tcptraceroute 等价于 traceroute -T

lft:第四层traceroute,执行tcptraceroute,像 traceroute -T,但尝试提供兼容原始的这类实现。

常用选项

  • -4, -6:显示强制使用IPv4或IPv6。
  • -I:使用ICMP ECHO进行探测。
  • -T:使用TCP SYN进行探测。
  • -F:不要分帧探测包。
  • -f first_ttl:指定TTL的起始值,默认是1。
  • -i interface:从指定网络接口来发送探测包。
  • -m max_ttl:指定TTL的最大值,默认是30。
  • -N squeries:指定同时发送的探测包数量,默认是16。
  • -n:不要进行域名解析,以数字形式显示地址。
  • -w waittime:设置等待探测响应的时间,单位秒,默认是5s。
  • -q nqueries:设置每个hop(路由跳)的探测包数量,默认是3。
  • -s source_addr:设置探测包的来源IP地址。
  • -r:跳过普通的路由表,直接将数据包发送到远程主机。
  • --mtu:发现跟踪路径上的最大传输单元大小(MTU)
  • --back:打印返回路径的hop(路由跳),如果看起来跟去的方向的不一样。

举例

跟踪我的VPS的路由情况。

# traceroute -n coderbee.net
traceroute to coderbee.net (198.56.238.193), 30 hops max, 40 byte packets
1  192.168.203.1 (192.168.203.1)  0.611 ms   0.574 ms   0.660 ms
2  120.197.59.129 (120.197.59.129)  3.492 ms * *
3  120.196.2.125 (120.196.2.125)  2.370 ms 120.196.2.37 (120.196.2.37)  2.883 ms *
4  120.196.0.233 (120.196.0.233)  60.483 ms   59.496 ms   55.585 ms
5  221.176.19.65 (221.176.19.65)  5.720 ms 221.176.19.81 (221.176.19.81)  3.383 ms *
6  221.176.24.10 (221.176.24.10)  2.647 ms * *
7  221.176.24.234 (221.176.24.234)  4.219 ms * 221.176.24.238 (221.176.24.238)  6.507 ms
8  223.118.10.2 (223.118.10.2)  6.271 ms 211.136.1.101 (211.136.1.101)  6.819 ms 223.118.10.22 (223.118.10.22)  6.259 ms
9  211.136.1.113 (211.136.1.113)  115.302 ms 223.118.2.126 (223.118.2.126)  179.434 ms 223.118.2.50 (223.118.2.50)  178.581 ms
10  * 206.223.143.122 (206.223.143.122)  184.423 ms *
11  * 64.71.153.34 (64.71.153.34)  181.901 ms 72.52.92.122 (72.52.92.122)  186.133 ms
12  199.48.68.42 (199.48.68.42)  185.233 ms * *
13  * 192.157.207.68 (192.157.207.68)  180.258 ms *
14  198.56.238.193 (198.56.238.193)  184.608 ms * *

tracert

tracert 是windows下的traceroute。

用法: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

选项说明

  • -d:以数字形式显示地址,不进行域名解析。
  • -h maximum_hops:指定经过的最大路由跳数量。
  • -j host-list:指定 Tracert 实用程序数据包所采用路径中的路由器接口列表。
  • -w timeout:等待探测包响应的毫秒数。
  • target_name:目标主机的名称或 IP 地址。

举例

跟踪我的VPS的路由情况。

<

pre>
C:\Documents and Settings\Administrator>tracert coderbee.net

Tracing route to coderbee.net [198.56.238.193]
over a maximum of 30 hops:

1 <1 ms <1 ms <1 ms 192.168.203.1
2 5 ms * 5 ms 120.197.59.129
3 2 ms * 3 ms 120.196.2.125
4 2 ms * 51 ms 120.196.0.233
5 6 ms 2 ms 5 ms 221.176.22.201
6 17 ms * 3 ms 221.176.18.114
7 * 4 ms 5 ms 221.176.24.150
8 9 ms * 9 ms 211.136.1.97
9 178 ms 185 ms 187 ms 223.118.2.34
10 185 ms * * he.net.coresite.com [206.223.143.122]
11 184 ms 190 ms 279 ms 64.71.153.34
12 183 ms * * dc03r01bg02.scalabledns.com [199.48.68.42]
13 187 ms 183 ms 192 ms dc03r01bg02.scalabledns.com [199.48.68.42]
14 * 185 ms 189 ms 198.56.238.193

Trace complete.


欢迎关注我的微信公众号: coderbee笔记,可以更及时回复你的讨论。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据