才子佳人博客

我的故事我讲述

TraceRoute(tracert)工作原理
 
来源:xjh  编辑:xjh  2011-12-05

Traceroute是用来侦测主机到目的主机之间所经路由情况的重要工具,也是最便利的工具。前面说到,尽管ping工具也可以进行侦测,但是,因为ip头的限制,ping不能完全的记录下所经过的路由器。所以Traceroute正好就填补了这个缺憾。

TraceRoute程序的实现主要涉及IP头部生存时间(time to live, TTL)字段的使用。

设置TTL字段的目的是为了防止数据报由于选路错误或其他软硬件原因从而导致在网络中无休止的流动,TTL字段指定了数据报的生存时间。TTL的初始值由源主机设置,当一份数据报经过路由器时,处理该数据报的路由器都需要把TTL值减去数据报在路由器中停留的秒数。但事实上大多数路由器只是简单地将TTL值减1,因此TTL字段最终被实现为一个跳站计数器。当TTL字段的值被减为0时,路由器就不会转发该数据报,而是将其丢弃,并产生一份ICMP超时差错报文发往源主机以通知错误的发生。TraceRoute程序的关键就在于返回的这份ICMP超时差错报文的源地址就是途经路由器的IP地址。由此,通过依次递增TTL字段的值,就可以得到一份数据报在其传输路径上所经过的路由信息。

TraceRoute程序在具体实现时,是令其向目的主机发送一个ICMP回显请求(Echo request)消息,并重复递增IP头部TTL字段的值。刚开始的时候TTL等于1,这样当该数据报抵达途中的第一个路由器时,TTL的值就被减为0,导致发生超时错误,因此该路由器生成一份ICMP超时差错报文返回给源主机。随后,主机将数据报的TTL值递增1,以便IP报文能传递到下一个路由器,下一个路由器将会生成ICMP超时超时差错报文返回给源主机。不断重复这个过程,直到数据报到达最终的目的主机,此时目的主机将返回ICMP回显应答(Echo replay)消息。这样,源主机只需对返回的每一份ICMP报文进行解析处理,就可以掌握数据报从源主机到达目的主机途中所经过的路由信息。

TRACEROUTE 用法

[root@vmlinuxserver ~]# man traceroute
TRACEROUTE(8)

NAME

traceroute - print the route packets take to network host

SYNOPSIS

traceroute [ -dFInrvx ] [ -f first_ttl ] [ -g gateway ]

[ -i iface ] [ -m max_ttl ] [ -p port ]

[ -q nqueries ] [ -s src_addr ] [ -t tos ]

[ -w waittime ] [ -z pausemsecs ]

host [ packetlen ]

DESCRIPTION

The Internet is a large and complex aggregation of network hardware, connected together by gateways. Tracking the route one<A1><AF>s packets follow (or finding the miscreant gat
eway

that<A1><AF>s discarding your packets) can be difficult. Traceroute utilizes the IP protocol <A1><AE>time to live<A1><AF> field and attempts to elicit an ICMP TIME_EXCEEDED response f
rom each gateway

along the path to some host.

The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 40 bytes, but this may be increased by specifying a packet length (in

bytes) after the destination host name.

Other options are:

-f Set the initial time-to-live used in the first outgoing probe packet.

-F Set the "don<A1><AF>t fragment" bit.

-d Enable socket level debugging.

-g Specify a loose source route gateway (8 maximum).

-i Specify a network interface to obtain the source IP address for outgoing probe packets. This is normally only useful on a multi-homed host. (See the -s flag for another way

to do this.)

-I Use ICMP ECHO instead of UDP datagrams.

-m Set the max time-to-live (max number of hops) used in outgoing probe packets. The default is 30 hops (the same default used for TCP connections).

traceroute exmaple for linux

tracert usage for windows
tracertexample for windows

参考来源:cnblogs
http://www.itale.cn/archives/2011/12/20111202154044.html(ping 原理及ICMP协议简介)
http://www.cnblogs.com/wangyile/archive/2010/08/26/1809023.html
http://www.itale.cn/archives/2010/5/20100527163208.html(TTL生存时间简介)


分类:网络日志| 查看评论
相关文章
文章点击排行
本年度文章点击排行
发表评论:
  • 昵称: *
  • 邮箱: *
  • 网址:
  • 评论:(最多100字)
  • 验证码: