traceroute命令——判断网络是否正常连接、路径可达性

traceroute是Unix和类Unix系统中的一个命令,用于诊断和跟踪网络数据包从源主机到目标主机的路由路径。它通过发送一系列的Internet控制消息协议(ICMP)回显请求(ping)数据包来实现。一条路径上的每个设备traceroute要测3次。输出结果中包括每次测试的时间(ms)和设备的名称(如有的话)及其IP地址。
以下是对traceroute命令的详细解释:

1. 命令格式:

traceroute [选项] 目标主机

选项:

  • -I:使用ICMP Echo请求代替UDP数据包。
  • -T:使用TCP SYN(同步)请求代替UDP数据包。
  • -U:使用UDP数据包。
  • -q <查询数>:指定每个跃点上发送的查询数,默认为3。
  • -w <超时时间>:指定等待每个回显请求的超时时间(以秒为单位),默认为5s。
  • -m <跳数>:指定最大跃点数,默认为30。
  • -p: 设置UDP传输协议的通信端口。
  • -n:使用此选项时,traceroute将不会尝试将IP地址解析为主机名。

功能:

traceroute命令通过发送一系列的ICMP或UDP数据包,逐跳地确定到达目标主机的路径。每个数据包都在IP头的TTL字段中具有不同的值,以便在每一跳上确定路径。当一个数据包到达跳数的上限或目标主机时,它将被丢弃,并返回信息给发送者。traceroute命令显示每个跳点的IP地址和主机名,以及在每个跳点上的往返时间(RTT)。
工作原理请参考:https://blog.csdn.net/lida2003/article/details/125383921

使用示例:

  • traceroute www.google.com:跟踪到达Google的路径。
  • traceroute -I 8.8.8.8:使用ICMP Echo请求,跟踪到达Google DNS服务器的路径。
  • traceroute -m 10 www.example.com:指定最大跳数为10,跟踪到达达示例网站的路径。
[root@localhost ~]# traceroute www.baidu.com
traceroute to www.baidu.com (153.3.238.110), 30 hops max, 60 byte packets
 1  gateway (192.168.159.2)  0.251 ms  0.189 ms  0.174 ms
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 6  * * *	//记录按序列号从1开始,每个纪录就是一跳 ,每跳表示一个网关,我们看到每行有三个时间,单位是 ms,其实就是-q的默认参数。
 7  * * *	//探测数据包向每个网关发送三个数据包后,网关响应后返回的时间;如果您用 `traceroute -q 4 www.58.com` ,表示向每个网关发送4个数据包。
 8  * * *
 9  * * *
10  * * *
11  * * *
12  * * *
13  * * *
14  * * *
15  * * *
16  * * *
17  * * *
18  * * *
19  * * *
20  * * *
21  * * *
22  * * *
23  * * *
24  * * *
25  * * *
26  * * *
27  * * *
28  * * *
29  * * *
30  * * *
[root@localhost ~]#
[root@localhost ~]# traceroute 192.168.159.1
traceroute to 192.168.159.1 (192.168.159.1), 30 hops max, 60 byte packets
 1  192.168.159.1 (192.168.159.1)  1.689 ms * *
[root@localhost ~]#
[root@localhost ~]# traceroute 192.17.323.12
192.17.323.12: 未知的名称或服务
Cannot handle "host" cmdline arg `192.17.323.12' on position 1 (argc 1)
[root@localhost ~]# 
  • traceroute -n www.baidu.com:显示IP地址,不查主机名
  • traceroute -p 6888 www.baidu.com :探测包使用的基本UDP端口设置6888
  • traceroute -q 4 www.baidu.com :把探测包的个数设置为值4
[root@localhost ~]# traceroute -q 4 www.baidu.com
traceroute to www.baidu.com (153.3.238.102), 30 hops max, 60 byte packets
 1  gateway (192.168.159.2)  0.228 ms  0.269 ms  0.215 ms  0.244 ms
 2  * * * *
 ...
  • traceroute -r www.baidu.com:绕过正常的路由表,直接发送到网络相连的主机
[root@localhost ~]# traceroute -r www.baidu.com
traceroute to www.baidu.com (153.3.238.102), 30 hops max, 60 byte packets
connect: 网络不可达
[root@localhost ~]#
  • traceroute -w 3 www.baidu.com :把对外发探测包的等待响应时间设置为3秒

traceroute命令对于网络故障排除和帮助确定网络延迟问题非常有用。通过观察路径中的跳点,可以了解到达目标主机所经过的网络节点,并判断网络连接质量以及延迟情况。

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、付费专栏及课程。

余额充值