網際網路控制消息協議


網際網路控制消息協議 (简体)

網路協議
應用層
DHCP · DNS · FTP · Gopher · HTTP · IMAP4 · IRC · NNTP · XMPP · POP3 · SIP · SMTP · SNMP · SSH · TELNET · RPC · RTCP · RTP ·RTSP · SDP · SOAP · GTP · STUN · NTP · SSDP · 更多
傳輸層
TCP · UDP · TLS · DCCP · SCTP · RSVP · PPTP · 更多
網路層
IP (IPv4 · IPv6) ·

ICMP · ICMPv6 · IGMP · RIP ·

OSPF · BGP · IS-IS · IPsec · 更多
資料鏈結層
802.11 · 802.16 · Wi-Fi · WiMAX · ARP · RARP · ATM · DTM · 令牌環 · 乙太網 · FDDI · 幀中繼 · GPRS · EVDO · HSPA · HDLC · PPP · L2TP · ISDN · 更多
實體層
乙太網路實體層 · 數據機 · PLC · SONET/SDH · G.709 · 光導纖維 · 同軸電纜 · 雙絞線 · 更多
本模板: 檢視  討論  編輯  歷史

網際網路控制消息協議Internet Control Message Protocol 或簡寫 ICMP)的目的是用於在 TCP/IP 網路中發送控制消息,提供可能發生在通信環境中的各種問題反饋,通過這些信息,令管理者可以對所發生的問題作出診斷,然後採取適當的措施去解決它。

ICMP [1] 依靠IP來完成它的任務,它是IP的主要部分。它與傳輸協議,如TCPUDP顯著不同:它一般不用於在兩點間傳輸數據。它通常不由網路程序直接使用,除了pingtraceroute這兩個特別的例子。

IPv4的ICMP也叫ICMPv4。IPv6的也有一個相似的協議,叫ICMPv6。

目錄

技術細節

ICMP消息是在IP層,通常是從一個普通的產生了ICMP響應的IP數據報中生成的。IP把適當的ICMP消息用一個新的檔頭(header)封裝起來(以把ICMP消息送回原來的發送者),然後把產生的數據報用常規的方式傳送回去。

例如,每台轉發IP數據報的機器(例如途中的路由器)都要把IP報頭中的TTL(time to live)減1,如果TTL減為了0,一個ICMP超時消息就會被發送到數據報的源發送者。

每個ICMP消息都是直接封裝在一個IP數據報中的,因此,和UDP一樣,ICMP是不可靠的。

雖然ICMP是包含在IP數據報中的,但是對ICMP消息通常會特殊處理,會和一般IP數據報的處理不同,而不是作為IP的一個子協議來處理。在很多時候,需要去查看ICMP消息的內容,然後發送適當的錯誤消息到那個原來產生IP數據包的程序,即那個被提示一個ICMP消息的程序。

很多常用的工具是基於ICMP消息的。traceroute是通過發送包含有特殊的TTL的包,然後查找ICMP超時消息和目標不可達消息來實現的。和traceroute相關的ping則是用ICMP的"Echo request"和"Echo reply"消息來實現的。

ICMP部分的結構

報頭

ICMP報頭從IP報頭的第160位開始(除非使用了IP報頭的可選部分)。

Bits 160-167 168-175 176-183 184-191
160 Type Code 較驗碼(checksum)
192 ID 序號(sequence)
  • Type - ICMP的類型;
  • Code - 進一步劃分ICMP的類型;例如,ICMP的目標不可達類型可以把這個位設為1至15等來表示不同的意思。
  • Checksum - 這個欄位包含有從ICMP報頭和數據部分計算得來的,用於檢查錯誤的數據,with value 0 for this field.
  • ID - 這個欄位包含了ID值,在ECHO REPLY類型的消息中要返回這個欄位。
  • Sequence - 這個欄位包含一個序號,同樣要在ECHO REPLY類型的消息中要返回這個欄位。

填充數據

填充的數據緊接在ICMP報頭的後面(以8位為一組):

  • Linux的 "ping"工具填充的ICMP除了8個8位元組的報頭以外,還另外填充數據使得總大小為64位元組。
  • Windows 的"ping.exe" 填充的ICMP除了8個8位元組的報頭以外,還另外填充數據使得總大小為40位元組

可能的消息列表 (不是全部)

Type Code Description
0 - Echo Reply 0 Echo reply (used to ping)
1 and 2 Reserved
3 - 目的地不可到達 0 Destination network unreachable
1 Destination host unreachable
2 Destination protocol unreachable
3 Destination port unreachable
4 Fragmentation required, and DF flag set
5 Source route failed
6 Destination network unknown
7 Destination host unknown
8 Source host isolated
9 Network administratively prohibited
10 Host administratively prohibited
11 Network unreachable for TOS
12 Host unreachable for TOS
13 Communication administratively prohibited
4 - Source Quench 0 Source quench (congestion control)
5 - Redirect Message 0 Redirect Datagram for the Network
1 Redirect Datagram for the Host
2 Redirect Datagram for the TOS & network
3 Redirect Datagram for the TOS & host
6 Alternate Host Address
7 Reserved
8 - Echo Request 0 Echo request
9 - Router Advertisement 0 Router Advertisement
10 - Router Solicitation 0 Router discovery/selection/solicitation
11 - Time Exceeded 0 TTL expired in transit
1 Fragment reassembly time exceeded
12 - Parameter Problem: Bad IP header 0 Pointer indicates the error
1 Missing a required option
2 Bad length
13 - Timestamp 0 Timestamp
14 - Timestamp Reply 0 Timestamp reply
15 - Information Request 0 Information Request
16 - Information Reply 0 Information Reply
17 - Address Mask Request 0 Address Mask Request
18 - Address Mask Reply 0 Address Mask Reply
19 Reserved for security
20 through 29 Reserved for robustness experiment
30 - Traceroute 0 Information Request
31 Datagram Conversion Error
32 Mobile Host Redirect
33 Where-Are-You (originally meant for IPv6)
34 Here-I-Am (originally meant for IPv6)
35 Mobile Registration Request
36 Mobile Registration Reply
37 Domain Name Request
38 Domain Name Reply
39 SKIP Algorithm Discovery Protocol, Simple Key-Management for Internet Protocol
40 Photuris, Security failures
41 ICMP for experimental mobility protocols such as Seamoby [RFC4065]
42 through 255 Reserved

參考

  1. ^ RFC 792 INTERNET CONTROL MESSAGE PROTOCOL; DARPA INTERNET PROGRAM; PROTOCOL SPECIFICATION; Introduction,J. Postel,Internet RFC/STD/FYI/BCP Archives,1981年9月1日.於2008年5月16日查閱. 

外部連結







stock | retire | vm
Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History