traceroute命令详解

时间:2024.4.21

traceroute命令详解 默认分类 2010-04-06 16:50:33 阅读593 评论0 字号:大中小 订阅

定义:

互联网中,信息的传送是通过网中许多段的传输介质和设备(路由器,交换机,服务器,网关等等)从一端到达另一端。每一个连接在Internet上的设备,如主机、路由器、接入服务器等一般情况下都会有一个独立的IP地址。通过Traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一样,但基本上来说大部分时候所走的路由是相同的。UNIX系统中,我们称之为Traceroute,MS Windows中为Tracert。 Traceroute通过发送小的数据包到目的设备直到其返回,来测量其需要多长时间。一条路径上的每个设备Traceroute要测3次。输出结果中包括每次测试的时间(ms)和设备的名称(如有的话)及其IP地址。

在大多数情况下,作为网络工程技术人员或者系统管理员会在UNIX主机系统下,直接执行命令行:

Traceroute hostname

而在Windows系统下是执行Tracert的命令:

Tracert hostname

比如在北京地区使用windows NT 主机(已经与北京163建立了点对点的连接后)

使用NT系统中的Tracert命令:(用户可用:开始->运行,输入"command" 调出command窗口使用此命令)traceroute [-46dFITUnrAV] [-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]

host [packetlen]

traceroute6 [options]

tracert [options]

tcptraceroute [options]

说明:

traceroute tracks the route packets take across an IP network on their way to a given host. It utilizes the IP protocol’s time to live (TTL) field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to the host.

traceroute6 = traceroute -6

tracert = traceroute -I

tcptraceroute = traceroute -T -p 80

选项说明:

唯一所必须的参数host是目的主机的名字或 IP 地址。在这个参数之后可以选择跟上探测包的大小[packetlen](默认是40)。改变包的大小并使用 -F 参数 可以用于获得个别网络跳的 MTU 信息。(探测包大小的参数对于TCP探测来说无用)。 其余的选项 :

--help 打印帮助信息,并退出。

-4, -6 显示地指定使用IPv4或IPv6 traceroute。默认情况下,traceroute会解析给定的主机名,并自动选择合适的协议。如果解析主机名既得到了IPv4的地址,又得到了IPv6的地址,traceroute会使用IPv4。

-I 使用ICMP ECHO进行探测。

-T 使用TCP SYN进行探测。

-U 使用UDP报文进行探测(默认情况)。对于无特权用户来说,只允许使用UDP报文进行探测。

-d 允许进行socket级别的调试(当Linux kernel支持它的时候)Enable socket level debugging (when the Linux kernel supports it)

-F 将“不要分段Don't Fragment”位置位。这将告诉中间路由器不要将该包分段(当路由器发现该探测包对于网络中MTU来说太大的时候)

-f <first_ttl>

设置第一个检测数据包的存活数值TTL的大小。默认是1 。

-g <gateway>

告诉traceroute为发出的packet增加IP源路由选项,以此告诉网络在路由该packet时需要通过指定的网关。不是十分有用,大多数的路由器因为安全方面的考虑将源路由设置为失效。

-i <interface>

指定traceroute发送包时经过的端口。默认的端口是依照路由表选定的。

-m <max_ttl>

指定traceroute将要探测的最大跳数(最大的生存时间)。默认值为30。

-N <squeries>

指定同时发送的探测包数目。同时发送几个探测包可以适当地加快traceroute的速度。默认值为15。注意:有些路由器和主机会使用ICMP速率限制,在这种情况下,指定同时发送大量的探测包会导致一些响应丢失。

-n 显示的时候无需将IP地址和主机名相对应。直接使用IP地址而非主机名称。

-p <port>

使用UDP的跟踪,基础的traceroute会使用指定的目的端口(每个探测包的目的端口号会递增)。

使用ICMP跟踪,指定初始的icmp序列号(每个探测包递增)。

使用TCP跟踪,指定要连接的端口号(常数)

-t <tos>

对于IPv4,设置服务类型(Type of Service,TOS)及优先值。有用的数值有16(低延迟)和8(高吞吐量)。注意在使用某些TOS优先值时,你必须是超级用户。

对于IPv6,设置流量控制值。

-w <waittime>

设置对探测包响应的等待时间(秒),默认值是5秒。

-q <nqueries>

设置每一跳的探测包数量。默认是3 。

-r 忽略普通的路由表,直接发送到所在网络(attacked network)的远端主机上。如果该主机不是直接附在网络

(directly-attached network)中,会返回一个错误。该选项可用于ping一个本地主机,而该主机所经过的端口没有路由。 -s <source_addr>

设置本地主机发出数据包的地址。注意你必须选择某一端口的地址,这个地址就是发出数据包的端口所使用的。

-z <sendwait>

探测包之间最小的时间间隔(默认值为0)。如果该值大于10,则它指定的为毫秒,否则,它指定的为秒(允许使用浮点数)。当某些路由器对ICMP报文实行速率限制时有用。

-A 在路由注册中查找AS path,并将结果直接打印在相应的地址后面

-V 打印出版本并退出。

This program attempts to trace the route an IP packet would follow to some internet host by launching a

probe packets with a small ttl (time to live) then listening for an ICMP "time exceeded" reply from a

gateway. We start our probes with a ttl of one and increase by one until we get an ICMP "port unreach-

able" (or TCP reset), which means we got to "host", or hit a max (which defaults to 30 hops). Three (by

default) probes are sent at each ttl setting and a line is printed showing the ttl, address of the gate-

way and round trip time of each probe. If the probe answers come from different gateways, the address of

each responding system will be printed. If there is no response within a 5.0 (default) seconds, a "*" is

printed for that probe.

We don’t want the destination host to process the UDP probe packets so the destination port is set to an

unlikely value (you can change it with the -p flag). There is no such problem for ICMP or TCP tracerout-

ing (for TCP we close sessions immediately after connect).

After the time some additional annotation can be printed: !H, !N, or !P (host, network or protocol

unreachable), !S (source route failed), !F (fragmentation needed), !X (communication administratively

prohibited), !V (host precedence violation), !C (precedence cutoff in effect), or !<num> (ICMP unreach-

able code <num>). If almost all the probes result in some kind of unreachable, traceroute will give up

and exit.


第二篇:ping和traceroute的区别


ping和traceroute原理分析---异同----为什么不能ping通却能traceroute

20xx年02月02日 星期五

ping和traceroute的区别

10:05

关于ping和trace命令,有2个发现

首先是ping和trace的不同,虽然都是ICMP协议,但是可以有ping过trace不过或者相反的情况

再一个是pc的ping&trace和UNIX/router的不同,曾发生过某些节点前者不能过但后者却能够过的情况,当时也和同事讨论过,也没讨论出个子丑寅卯来

不知道这有啥解释么?

关于你的第一个问题,是很正常的,因为ping和traceroute的原理不同,

对于ping,发送的是一个echo request包,类型为 8 0,当被ping者接到相关icmp包的时候,根据实际情况,逻辑是,就发回 reply 0 0,逻辑否,则根据具体情况发出一些其他的信息,总结起来的说,是看目的是否能及时的把icmp reply包送回到源,一当路径上的某个节点把reply包给deny掉了,就肯定ping不通了,比如会是time out,

下面是对ping的一些debug 输出,debug ip pa de 100,access-list 100 permit icmp any any,

1、这个是ping通的

Sending 5, 100-byte ICMP Echos to 192.168.100.1, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 36/51/68 ms

R4(config)#

*Mar 1 00:03:20.579: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.1 (Serial1/0), routed via FIB *Mar 1 00:03:20.583: IP: s=172.16.14.2 (local), d=192.168.100.1 (Serial1/0), len 100, sending *Mar 1 00:03:20.587: ICMP type=8, code=0

*Mar 1 00:03:20.639: IP: tableid=0, s=192.168.100.1 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB

*Mar 1 00:03:20.643: IP: s=192.168.100.1 (Serial1/0), d=172.16.14.2 (Serial1/0), len 100, rcvd 3 *Mar 1 00:03:20.647: ICMP type=0, code=0

2、有路由,ping不通的,我在R1上做了如下设置

access-list 100 deny icmp any any

access-list 100 permit ip any any

int s1/0

ip access-group 100 in

然后在R4上 do debug ip pa de 100

R4(config)#do ping 192.168.100.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.100.2, timeout is 2 seconds:

U.U.U

Success rate is 0 percent (0/5)

R4(config)#do debug ip pa de 100

IP packet debugging is on (detailed) for access list 100

R4(config)#

R4(config)#

R4(config)#do ping 192.168.100.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.100.2, timeout is 2 seconds:

U

*Mar 1 00:21:11.031: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:21:11.035: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 100, sending *Mar 1 00:21:11.039: ICMP type=8, code=0

*Mar 1 00:21:11.075: IP: tableid=0, s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB *Mar 1 00:21:11.079: IP: s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3

*Mar 1 00:21:11.083: ICMP type=3, code=13-----tcp/ip 上看出,3 13代码暗示着由于过滤,通讯被禁止

下面是有路由,因为reply包被deny而time out的,

我把R1上的acl设置改成

access-list 100 deny icmp any any

access-list 100 permit ip any any

int s1/0

ip access-group 100 out

R4(config)#do ping 192.168.100.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.100.2, timeout is 2 seconds:

*Mar 1 00:25:15.735: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:25:15.735: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 100, sending *Mar 1 00:25:15.735: ICMP type=8, code=0.

总结起来,ping能否成功有三个必要条件,1、互相有到达对端的路由,2、echo包没被禁止,3、别time out掉(这个实验不好做,本来想通过设置timeout时间为10ms来做,哈哈,最小是1s.)

对于traceroute,本质可以理解为hop by hop的ping,但这个ping和上面讲的ping不一样,这个ping和我们的ping命令不同,traceroute包发出去后,途经的每个站点都会发回一个 类型代码为11 0的icmp 包回去,到了终点,才回发送一个代码为3 3的icmp包回到源,下面是一个traceroute的debug 输出 R4(config)#do tracer 192.168.100.2

Type escape sequence to abort.

Tracing the route to

*Mar 1 00:47:11.567: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:47:11.571: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 28, sending *Mar 1 00:47:11.571: UDP src=49234, dst=33434

*Mar 1 00:47:11.599: IP: tableid=0, s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB *Mar 1 00:47:11.603: IP: s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3 *Mar 1 00:47:11.607: ICMP type=11, code=0

*Mar 1 00:47:20.643: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:47:20.643: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 28, sending *Mar 1 00:47:20.647: UDP src=49235, dst=33435

*Mar 1 00:47:20.707: IP: tableid=0, s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB *Mar 1 00:47:20.711: IP: s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3 *Mar 1 00:47:20.715: ICMP type=11, code=0

*Mar 1 00:47:20.719: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:47:20.723: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 28, sending *Mar 1 00:47:20.723: UDP src=49236, dst=33436

*Mar 1 00:47:20.767: IP: tableid=0, s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB *Mar 1 00:47:20.771: IP: s=172.16.14.1 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3 *Mar 1 00:47:20.775: ICMP type=11, code=0

*Mar 1 00:47:20.783: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:47:20.787: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 28, sending *Mar 1 00:47:20.791: UDP src=49237, dst=33437

*Mar 1 00:47:20.867: IP: tableid=0, s=172.16.123.2 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB

*Mar 1 00:47:20.871: IP: s=172.16.123.2 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3 *Mar 1 00:47:20.875: ICMP type=3, code=3

*Mar 1 00:47:26.903: IP: s=192.168.100.4 (Loopback0), d=255.255.255.255, len 71, unroutable *Mar 1 00:47:26.903: UDP src=57768, dst=53172.16.123.2

*Mar 1 00:47:29.907: IP: tableid=0, s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), routed via FIB *Mar 1 00:47:29.907: IP: s=172.16.14.2 (local), d=192.168.100.2 (Serial1/0), len 28, sending *Mar 1 00:47:29.911: UDP src=49238, dst=33438

*Mar 1 00:47:29.987: IP: tableid=0, s=172.16.123.2 (Serial1/0), d=172.16.14.2 (Serial1/0), routed via RIB

*Mar 1 00:47:29.991: IP: s=172.16.123.2 (Serial1/0), d=172.16.14.2 (Serial1/0), len 56, rcvd 3 *Mar 1 00:47:29.995: ICMP type=3, code=3

从输出中可以验证一些东西,比如traceroute进程每跳发出三个探测包,上面也是

中途站点R1的debug 输出

R1(config)#do debug ip pa de 100

IP packet debugging is on (detailed) for access list 100

R1(config)#

*Mar 1 00:47:20.311: IP: tableid=0, s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), routed via FIB *Mar 1 00:47:20.315: IP: s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), len 56, sending

*Mar 1 00:47:20.319: ICMP type=11, code=0

*Mar 1 00:47:29.387: IP: tableid=0, s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), routed via FIB *Mar 1 00:47:29.391: IP: s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), len 56, sending

*Mar 1 00:47:29.395: ICMP type=11, code=0

*Mar 1 00:47:29.467: IP: tableid=0, s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), routed via FIB *Mar 1 00:47:29.471: IP: s=172.16.14.1 (local), d=172.16.14.2 (Serial1/0), len 56, sending

*Mar 1 00:47:29.475: ICMP type=11, code=0

目的站点R2的输出

R2(config)#do un all

All possible debugging has been turned off

R2(config)#do debug ip pa de 100

IP packet debugging is on (detailed) for access list 100

R2(config)#

*Mar 1 00:53:49.315: IP: s=172.16.14.2 (Serial1/2.1), d=192.168.100.2, len 28, rcvd 0

*Mar 1 00:53:49.319: UDP src=49251, dst=33437

*Mar 1 00:53:49.319: IP: tableid=0, s=172.16.123.2 (local), d=172.16.14.2 (Serial1/2.1), routed via FIB *Mar 1 00:53:49.323: IP: s=172.16.123.2 (local), d=172.16.14.2 (Serial1/2.1), len 56, sending

*Mar 1 00:53:49.327: ICMP type=3, code=3

R2(config)#

*Mar 1 00:53:58.447: IP: s=172.16.14.2 (Serial1/2.1), d=192.168.100.2, len 28, rcvd 0

*Mar 1 00:53:58.451: UDP src=49252, dst=33438

*Mar 1 00:53:58.455: IP: tableid=0, s=172.16.123.2 (local), d=172.16.14.2 (Serial1/2.1), routed via FIB *Mar 1 00:53:58.455: IP: s=172.16.123.2 (local), d=172.16.14.2 (Serial1/2.1), len 56, sending

*Mar 1 00:53:58.459: ICMP type=3, code=3

*Mar 1 00:53:58.587: IP: s=172.16.14.2 (Serial1/2.1), d=192.168.100.2, len 28, rcvd 0

*Mar 1 00:53:58.591: UDP src=49253, dst=33439

由此可以看出,一样的道理,在中间站点上只要禁止代码11 0的icmp包输出,那么traceroute的输出中,关于那个站点就是*号了,或者在路上把代码为3 3 的禁止掉,一样会traceroute不通,而此时,ping通是一点问题都没有的,因为ping没有用到这些类型的icmp包,具体实验就不做了,时间紧张。

ping和traceroute的区别

ping和traceroute的区别

TraceRoute(tracert)实现原理

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报文进行解析处理,就可以掌握数据报从源主机到达目的主机途中所经过的路由信息。

1、ping目的是为了测试另一台主机是否可达。该程序发送一份I C M P回显请求报文给主机,并等待返回I C M P回显应答。

2、ping能否成功有三个必要条件,1、互相有到达对端的路由,2、echo包没被禁止,3、别time out掉

3、I P首部中的首部长度字段只有4 bit,因此整个I P首部最长只能包括1 5个32 bit长的字(即6 0个字节)。由于I P首部固定长度为2 0字节, R R选项用去3个字节,这样只剩下3 7个字节( 6 0-2 0-3)来存放I P地址清单,也就是说只能存放9个I P地址。

4、I P首部中留给选项的空间有限,不能存放当前大多数的路径。在I P首部选项字段中最多只能存放9个I P地址。

5、traceroute程序使用I C M P报文和I P首部中的T T L字段(生存周期)。每个处理数据报的路由器都需要把T T L的值减1 ,如果其T T L字段是0或1,则路由器不转发该数据报 这种数据报的目的主机可以将它交给应用程序,这是因为不需要转发该数据报。但是在通常 情况下,系统不应该接收T T L字段为0的数据报)。相反,路由器将该数据报丢弃,并给信源机发一份I C M P“超时”信息。

6、traceroute程序发送一份U D P数据报给目的主机,但它选择一个不可能的值作为U D P端口号(大于30 000),使目的主机的任何一个应用程序都不可能使用该端口。因为,当该数据报到达时,将使目的主机的U D P模块产生一份“端口不可达”错误的I C M P报文。

7、对于traceroute,本质可以理解为hop by hop的ping,但这个ping和上面讲的ping不一样,这个ping和我们的ping命令不同,traceroute包发出去后,途经的每个站点都会发回一个 类型代码为11 0的icmp 包回去,到了终点,才回发送一个代码为3 3的icmp包回到源。

8、在中间站点上只要禁止代码11 0的icmp包输出,那么traceroute的输出中,关于那个站点就是*号了,或者在路上把代码为3 3 的禁止掉,一样会traceroute不通,而此时,ping通是一点问题都没有的,因为ping没有用到这些类型的icmp包。

更多相关推荐:
Cover Letter Examples求职信范文5例

CoverLetterExamplesMarilynAppleton12300HilltopDriveMantanaCA994449193455566DateMaxwellJonesGancoEngineering4567Main...

cover letter 求职信范文 2篇

sample1DearMrWangIamafreshgraduatefromXiamenUniversityofTechnologyandIamwritinginresponsetoyouradvertisem...

Cover letter-范文

DAVIDEmailCurrentAddressPermanentAddressSkypeName01May20xxMrXuCollegeofForeignLanguagesDearMrXuPleaseacceptthiscove...

Cover Letter模板范例

DearEditorsWefeelsorrytobotheryouafewminutesduringyourworktoreadthisOurauthorsareallinblissthatwecanshowyouourlabor...

cover letter注意事项及范文

Coveringletters即求职信是简历里的一部分一般在求职信中简要介绍自己的情况以及你要申请的职位或者在你了解某个公司招聘的具体位置后表达自己有意从事这个职位的意愿说明自己有做好这个职位的经验和能力同时也...

cover letter范文

DeareditorIamastudentofBeijingUniversityofTechnologyinChinaIwouldliketosubmitthearticlexxxtoProgressinChemistryIpro...

cover letter 范文

DearMrGauthierFromZHILIANwebsiteIlearnedaboutyourneedforastockbrokerIamveryinterestedinthisprojectandbelievethatmyb...

cover-letter

GeLisha405room5thbuildingfirstdormitoryXiamenUniversityofTechnology600LigongRoadJimeiXiamenPRC361024059015959349389...

经典求职信背诵 Cover Letter of Job ApplicationMicrosoft Word 文档

经典求职信背诵CoverLetterofJobApplication来源考研英语高分作文经典背诵100篇印建坤宋平明林梦茜日期20xx1128DirectionsYouhavelearntfromtheuniv...

Cover Letter & Title & Citation

WritingandTranslationClass5谢鹤轩Xiehexuan20xx111390CoverLetterXiehexuanNo4StudentDormitoryBuildingNo10Xituc...

Cover-Letter-Template

SalutationDearinsertnameofhiringmanagerBodyFirstparagraphMentionthejobyoureapplyingforandwhereyoufoundthejoblisting...

怎么写Cover Letter

怎么写CoverLetter附工作广告和CoverLetter样本第一次陶瓷可借鉴申请博士后和教职或工业界工作时CoverLetter都是必备的CoverLetter是用来简要的介绍一下你自己表现你为什么适合你...

cover letter(46篇)