traceroute命令用法举例

通过traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。
当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一样,但基本上来说大部分时候所走的路由是相同的。l
inux系统中,我们称之为traceroute,在MS Windows中为tracert。 traceroute通过发送小的数据包到目的设备直到其返回,来测量其需要多长时间。
一条路径上的每个设备traceroute要测3次。输出结果中包括每次测试的时间(ms)和设备的名称(如有的话)及其IP地址。

在大多数情况下,我们会在linux主机系统下,直接执行命令行:

traceroute hostname

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

tracert hostname

1.命令格式:traceroute[参数][主机]

2.命令功能:traceroute指令让你追踪网络数据包的路由途径,预设数据包大小是40Bytes,用户可另行设置。

具体参数格式:traceroute [-dFlnrvx][-f<存活数值>][-g<网关>...][-i<网络界面>][-m<存活数值>][-p<通信端口>][-s<来源地址>][-t<服务类型>][-w<超时秒数>][主机名称或IP地址][数据包大小]

3.命令参数:
-d 使用Socket层级的排错功能。

-f 设置第一个检测数据包的存活数值TTL的大小。

-F 设置勿离断位。

-g 设置来源路由网关,最多可设置8个。

-i 使用指定的网络界面送出数据包。

-I 使用ICMP回应取代UDP资料信息。

-m 设置检测数据包的最大存活数值TTL的大小。

-n 直接使用IP地址而非主机名称。

-p 设置UDP传输协议的通信端口。

-r 忽略普通的Routing Table,直接将数据包送到远端主机上。

-s 设置本地主机送出数据包的IP地址。

-t 设置检测数据包的TOS数值。

-v 详细显示指令的执行过程。

-w 设置等待远端主机回报的时间。

-x 开启或关闭数据包的正确性检验。

4.使用实例:
4.1 traceroute 用法简单、最常用的用法
命令:traceroute www.baidu.com 

[moiaopr@CNSZ443239 ~]$ traceroute www.baidu.com
traceroute to www.baidu.com (14.215.177.37), 30 hops max, 60 byte packets
 1  10.14.192.1 (10.14.192.1)  2.021 ms  2.170 ms  1.983 ms
 2  10.14.241.213 (10.14.241.213)  4.309 ms  0.346 ms  4.270 ms
 3  * * *
 4  * * *

说明:

记录按序列号从1开始,每个纪录就是一跳 ,每跳表示一个网关,我们看到每行有三个时间,单位是 ms,其实就是-q的默认参数。探测数据包向每个网关发送三个数据包后,网关响应后返回的时间;

如果您用traceroute -q 4 www.58.com ,表示向每个网关发送4个数据包(即每一条就是4行带*号的数据)。 

有时我们traceroute 一台主机时,会看到有一些行是以星号表示的。出现这样的情况,可能是防火墙封掉了ICMP的返回信息,所以我们得不到什么相关的数据包返回数据。

有时我们在某一网关处延时比较长,有可能是某台网关比较阻塞,也可能是物理设备本身的原因。

当然如果某台DNS出现问题时,不能解析主机名、域名时,也会 有延时长的现象;您可以加-n 参数来避免DNS解析,以IP格式输出数据。

如果在局域网中的不同网段之间,我们可以通过traceroute 来排查问题所在,是主机的问题还是网关的问题。

如果我们通过远程来访问某台服务器遇到问题时,我们用到traceroute 追踪数据包所经过的网关,提交IDC服务商,也有助于解决问题;

但目前看来在国内解决这样的问题是比较困难的,就是我们发现问题所在,IDC服务商也不可能帮助我们解决。

4.2 跳数设置
命令:
traceroute -m 10 www.baidu.com

[moiaopr@CNSZ443239 ~]$ traceroute -m 10 www.baidu.com
traceroute to www.baidu.com (14.215.177.38), 10 hops max, 60 byte packets
 1  10.14.192.1 (10.14.192.1)  1.935 ms  1.946 ms  1.929 ms
 2  10.14.241.213 (10.14.241.213)  0.190 ms  0.187 ms  0.157 ms
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  * * *
10  * * *
[moiaopr@CNSZ443239 ~]$ 

4.3 显示IP地址,不查主机名
命令:traceroute -n www.baidu.com

[moiaopr@CNSZ443239 ~]$ traceroute -n www.baidu.com
traceroute to www.baidu.com (14.215.177.37), 30 hops max, 60 byte packets
 1  10.14.192.1  1.986 ms  1.962 ms  1.916 ms
 2  10.14.241.213  1.005 ms  0.976 ms  0.123 ms
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DDU ICMP controls consist of 3 controls : TDDUOSPING - A non blocking PING protocolTDDUOSTRACEROUTE - A non blocking TraceRoute ProtocolTDDUOSDNS - A non blocking ARP/RARP controlAbout TDDUOSDNS :Host names are resolved to IP addresses, and IP address can be resolved to host names. If you enter an IP into the ADDRESS property, the HOST property will be completed, and the OnHostLookup event will occur. If you enter an IP or a HOST name into the HOST property, the ADDRESS property will be completed, and the OnAddressLookup event will occure. The runtime property OK can be queried to see if the lookup was successful. To reduce lookup overhead, an IP/Hostname cache can be used by setting the UseIPCache property to true. The cache is only persistent for the current session, and maynot be saved between sessions. You can use FlushIPCache method to clear the cache.When combined with the other controls in this package, the delay normally associated with connecting a socket can be avoided. Each control must have a unique TDDUOSDNS control.About the Demo :The demo project shows how to use each control. The TDDUOSDNS control is shown both in combination with other controls, and used independantly. DNS not an ICMP protocol, but it is included to prevent the windows application from blocking.Blocking is when your windows program stops responding to messages, waiting for a call to return. Normally, all calls blocks for a very short time, and is not noticable - but when you have to wait for 5 or 10 seconds or even longer, the application can appear to be crashed. By using threads, callback messages, and events, I have illustrated how it is possible to avoid blocking in an application.These controls form a custom set of TCP/IP controls I have been developing over the past year. The ICMP controls were written over the period of a week, and I consulted several references for information. I would like to thank Quinn Shute for his excellent book "Windows Socket Network Programming&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值