欢迎光临散文网 会员登陆 & 注册

【太阁课堂】Ping 和 traceroute 的工作原理以及作用+实验

2023-02-03 13:19 作者:太阁网络  | 我要投稿

在工作中,我们会经常使用ping 和traceroute 来检测网络的连通性,那么今天就给大家分析一下这两个小工具的工作原理以及常用的可选项参数的具体含义:

 

(1)Ping 的工作过程


 

Ping 会发送 echo request message 到某个地址,然后等待应(reply),当 echo request 到达目标地址以后,在一个有效的时间内(timeout 之前)返回 echo reply message 给源地 址,则说明目的地可达。如在有效时间内,没有收到回应,则在发送端显示超时。


Ping 命令是把 ICMP 报文中的标示符置为发送该 ICMP 报文的进程,这样在对端可以区 分出从本端运行的多个 Ping 实例。Ping 命令每发送一个 ICMP 回显请求报文,顺序号就加 1,顺序号从 1 开始,不同的系 统发送回显请求的数量不同,默认情况发送 5 个回显请求报文。


也可以通过命令行参数设 置发送回显请求报文的个数,如果对端可达,则在对端会相应回应 5 个和请求端同样序号 的 ICMP 回应报文。 


(2)Tracert 的工作过程 

 

 

 

源端首先发送 3 个 TTL 字段的值都为 1 的 UDP 数据报给远程设备,使用随机的任何大 于 32768 的端口地址作为目标设备的接受报文端口,TTL 为 1 的数据报到达第一跳路由器以后 随即超时,路由器响应源设备一个 ICMP 的超时报文,之后源端再发送 3 个 UDP 数据报, 这次更改 TTL 值为 2,即经过 2 个路由器以后,响应源端 ICMP 超时报文,依次类推,直到 这些 UDP 报文到达了目标设备。


由于发送的报文中的目的端口,目标设备接收到 ICMP 报文后,由于报文的端口是一个 在目标设备没有使用的端口,目标设备就会响应 ICMP port unreachable 信息给源端,表示 目标端口不可达,同时说明 Tracert 执行完毕。从而可以从源端显示的结果中,看到到目标 设备所经过的路径。 


Tracert 发送数据报的 TTL 值最大可以到 30,每一次发送如果在指定的时间的内没有回 应报文,在发送端就会显示超时,如果发送 30 跳的值后,仍然显示为超时,表明无法达到 目标设备,测试失败。默认情况没有发送报文的超时时间为 5 秒,可以在 0ms~65535ms 之 间进行设置。


IPv4 网络环境:(H3C 设备上需要开启) 需要在中间设备(源端与目的端之间的设备)上开启 ICMP 超时报文发送功能。如果中 间设备是 H3C 设备,需要在设备上执行 ip ttl-expires enable 命令 需要在目的端开启 ICMP 目的不可达报文发送功能。


如果目的端是 H3C 设备,需要在设 备上执行 ip unreachables enable 命令。


实验:

实验环境,在R1和R3 上分别配置环回口,三个路由器之间使用OSPF 全部宣告到Area 0 .

实验一:ping 的使用


以下是常用的一些命令

[R1]ping ?

  -a             Select source IP address, the default is the IP address of the

                 output interface

  -c             Specify the number of echo requests to be sent, the default is

                 5

  -f             Set Don't Fragment flag in packet (IPv4-only)

  -h             Specify TTL value for echo requests to be sent, the default is

                 255

  -i             Select the interface sending packets

 

 

  -name          Display the host name of the destination address

 

  -s             Specify the number of data bytes to be sent, the default is

                 56bytes

  -si            Set the specified interface as the source interface of ping

                 packet

  ip             IP Protocol

  ipv6           IPv6 Protocol

 

这些参数是可以结合使用的, 比如检查链路MTU 。



配置解释

[R1]ping -a 1.1.1.1 -s 1500 3.3.3.3 

如图, 是在R1 上使用1.1.1.1 作为源地址, 3.3.3.3 作为目的地址,发送数据包大小为1500

实验二:tracert的使用

以下是常用的一些命令

[R1]tracert ?

  -a             Set source IP address, the default is the IP address of the

                 output interface

  -f             First time to live, the default is 1

  -m             Max time to live, the default is 30

  -name          Display the host name of the router on each hop

  -p             Destination UDP port number, the default is 33434

  -q             Number of probe packet, the default is 3

  ipv6           IPv6 Protocol

 


配置解释

[R1]tracert -a 1.1.1.1 3.3.3.3 以1.1.1.1 为源,3.3.3.3 为目的地探测每一跳路径

[R1]tracert -a 1.1.1.1 -f 2 3.3.3.3 指定以1.1.1.1 为源3.3.3.3 为目的地,每次ttl都为2,探测路径,隔跳探测。

 


【太阁课堂】Ping 和 traceroute 的工作原理以及作用+实验的评论 (共 条)

分享到微博请遵守国家法律