ICMP在RFC792中记述,指定了多种消息类型,这些消息的共同目的就是管理网络.ICMP消息可以分成错误信息,请求信息和相应信息,图1-16显示了一般的ICMP数据包格式。 这些数据包使用类型进行区分,不同的数据包都具有特定的类型,在数据包中的code区段进行标识,表1-6列出了不同ICMP数据包的类型以及他们的代码,RFC1700中有详细记载。 Figure 1-16. The ICMP packet header includes a type field, a code field that further identifies some types, and a checksum. The rest of the fields depend on the type and code.
Table 1-6. ICMP packet types and code fields. Type Code Name 0 0 ECHO REPLY 3 DESTINATION UNREACHABLE 0 Network Unreachable 1 Host Unreachable 2 Protocol Unreachable 3 Port Unreachable 4 Fragmentation Needed and Don't Fragment Flag Set 5 Source Route Failed 6 Destination Network Unknown 7 Destination Host Unknown 8 Source Host Isolated 9 Destination Network Administratively Prohibited 10 Destination Host Administratively Prohibited 11 Destination Network Unreachable for Type of Service 12 Destination Host Unreachable for Type of Service 4 0 SOURCE QUENCH (deprecated) 5 REDIRECT 0 Redirect Datagram for the Network (or Subnet) 1 Redirect Datagram for the Host 2 Redirect Datagram for the Network and Type of Service 3 Redirect Datagram for the Host and Type of Service 6 0 ALTERNATE HOST ADDRESS 8 0 ECHO 9 0 ROUTER ADVERTISEMENT 10 0 ROUTER SELECTION 11 TIME EXCEEDED 0 Time to Live Exceeded in Transit 1 Fragment Reassembly Time Exceeded 12 PARAMETER PROBLEM 0 Pointer Indicates the Error 1 Missing a Required Option 2 Bad Length 13 0 TIMESTAMP 14 0 TIMESTAMP REPLY 15 0 INFORMATION REQUEST (Obsolete) 16 0 INFORMATION REPLY (Obsolete) 17 0 ADDRESS MASK REQUEST (Near-obsolete) 18 0 ADDRESS MASK REPLY (Near-obsolete) 30 - TRACEROUTE
案例1-11和1-12显示了使用协议分析仪得到的用在ping功能的icmp的echo request和echo reply,这两个信息也是icmp消息中最常见的。 Example 1-11. ICMP Echo message, shown with its IPv4 header. Internet Protocol, Src Addr: 172.16.1.21 (172.16.1.21), Dst Addr: 198.133.219.25 (198.133.219.25) Version: 4 Header length: 20 bytes Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00) Total Length: 84 Identification: 0xabc3 (43971) Flags: 0x00 Fragment offset: 0 Time to live: 64 Protocol: ICMP (0x01) Header checksum: 0x8021 (correct) Source: 172.16.1.21 (172.16.1.21) Destination: 198.133.219.25 (198.133.219.25) Internet Control Message Protocol Type: 8 (Echo (ping) request) Code: 0 Checksum: 0xa297 (correct) Identifier: 0x0a40 Sequence number: 0x0000 Data (56 bytes)
虽然很多的ICMP能够承担一定的路由功能,但是比较重要的还是以下三个类型。 • 路由器通告和路由器选择,分别是类型九和类型时,用于IRDP(ICMP Router Discovery Protocol-icmp路由发现协议),用在一些操作系统中(微软的不同版本系统)查找本地路由器。 • 重定向,类型5,用来被路由器通知主机,到达特定目的的网关是数据链路上的另外一台路由器。 假设两个路由器,路由器A和路由器B连接在同一个以太网。 主机X也在一台网络中,同时配置了路由器A为缺省网关,,当主机发送数据包给路由器A,同时A查看这个数据包的目的地址发现该数据包需要经由路由器B转发(也就是说A会把这个数据包从原来的接收接口发出转发给B)。 路由器A在转发这个数据包的同时还会发送一个ICMP重定向信息给主机X,通告X以后发送这个特定数据时,直接把数据包发送给B,案例1-13显示了路由器发送重定向信息。 Example 1-13. Using the debugging function debug ip icmp, this router can be seen sending a redirect to host 10.158.43.25, informing it that the correct router for reaching destination 10.158.40.1 is reachable via gateway (gw) 10.158.43.10. Pip#debug ip icmp ICMP packet debugging is on ICMP: redirect sent to 10.158.43.25 for dest 10.158.40.1, use gw 10.158.43.10 0 Pip#
在主机连接多个网关时,一个可以避免重定向的技巧是主机使用自己的IP地址做为缺省网关。 这样主机就会对每一个地址都会进行ARP请求的发送,如果地址在本地链路中不存在,合适的路由器就会利用代理ARP进行回应。 关于这种避免重定向的策略是否有效存在争议,重定向虽然得以避免和减少,但是却增加了ARP的流量。 IOS中重定向默认是开启的,可以在接口下使用no ip redirects关闭。