深入浅出网工第二个协议---Internet控制报文协议ICMP
ICMP简介
ICMP错误报告
小结:
ICMP重定向
典型应用
PING应用
PING常用的配置参数说明如下
-a(source-ip-address)参数
ping 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=20 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/30/40 ms
在R1上查看到达3.3.3.3路由的出接口为R1的G0/0/0接口
display ip routing-table 3.3.3.3
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
3.3.3.3/32 Static 60 0 RD 12.1.1.2 GigabitEthernet
0/0/0
所以:默认情况下,R1访问目标地址的时候,所携带的源IP地址是12.1.1.1即自己的接口IP地址作为源IP地址访问目标IP地址验证-a参数的用法:
ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/28/30 ms
R1访问目标地址的时候,所携带的源IP地址是1.1.1.1即自己的loopback 0地址
-c(count)参数
指定发送ICMP ECHO-REQUEST报文次数。缺省情况下发送5个ICMP ECHO-REQUEST报文。
ping -c 1000 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=6 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=7 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=8 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=9 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=10 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=11 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=12 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=13 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=14 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
14 packet(s) transmitted
14 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/28/40 ms
-h(ttl-value)参数
指定TTL的值。缺省值是255。
ping -h 1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Request time out
Request time out
Request time out
Request time out
Request time out
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
ping -h 2 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/32/40 ms
-t(timeout)参数
指定发送完ICMP ECHO-REQUEST后,等待ICMP ECHO-REPLY的超时时间。
ping -t 31 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Request time out
Request time out
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=20 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
3 packet(s) received
40.00% packet loss
round-trip min/avg/max = 20/26/30 ms
注意:ping命令的输出信息中包括目的地址、ICMP报文长度、序号、TTL值、以及往返时间。序号是包含在Echo回复消息(Type=0)中的可变参数字段,TTL和往返时间包含在消息的IP头中。
TRACERT应用
tracert 30.0.0.2
Tracert to 30.0.0.2(30.0.0.2), max hops:30, packet length:40, press CTRL_C to break
1 10.0.0.2 130 ms 50 ms 40 ms
2 20.0.0.2 80 ms 60 ms 80 ms
3 30.0.0.2 80 ms 60 ms 70 ms
TRACERT常用的配置参数如下:
-a (source-ip-address)参数
指定tracert报文的源地址。
-f (first-ttl)参数
指定初始TTL。缺省值是1。
-m (max-ttl)参数
指定最大TTL。缺省值是30。
-name参数
使能显示每一跳的主机名。
-p (port)参数
指定目的主机的UDP端口号。
TRACERT原理
第一步:发送一个UDP报文,TTL值为1
RTA向目的端主机B发送一个UDP报文,TTL值为1,目的UDP端口号是大于30000的一个数,因为在大多数情况下,大于30000的UDP端口号是任何一个应用程序都不可能使用的端口号。第一跳(RTB)收到源端发出的UDP报文后,判断出报文的目的IP地址不是本机IP地址,将TTL值减1后,判断出TTL值等于0,则丢弃报文并向源端发送一个ICMP超时(Time Exceeded)报文(该报文中含有第一跳的IP地址10.0.0.2),这样源端就得到了RTB的地址。
第二步:发送一个UDP报文,TTL值为2
源端收到RTB的ICMP超时报文后,再次向目的端发送一个UDP报文,TTL值为2。第二跳(RTC)收到源端发出的UDP报文后,回应一个ICMP超时报文,这样源端就得到了RTC的地址(20.0.0.2)。
第N步:发送一个UDP报文,TTL值为N
以上过程不断进行,直到目的端收到源端发送的UDP报文后,判断出目的IP地址是本机IP地址,则处理此报文。根据报文中的目的UDP端口号寻找占用此端口号的上层协议,因目的端没有应用程序使用该UDP端口号,则向源端返回一个ICMP端口不可达(Destination Unreachable)报文。源端收到ICMP端口不可达报文后,判断出UDP报文已经到达目的端,则停止Tracert程序,从而得到数据报文从源端到目的端所经历的路径(10.0.0.2;20.0.0.2;30.0.0.2)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~