What is ICMP
ICMP (Internet Control Message Protocol) is a protocol used to exchange control messages and error notifications for IPv4 communication. It is defined in RFC 792.
IP itself has no mechanism to guarantee reliability, and no way to notify the sender when a packet fails to reach its destination. ICMP is an auxiliary protocol designed to report on the status of IP communication — unreachable destinations, errors encountered along the path, connectivity checks, and so on — and is never used to carry user data.
1. Like TCP and UDP, it sits above IP, but in practice it is often treated as part of the IP stack itself rather than as an independent transport-layer protocol. The equivalent function in IPv6 is provided by ICMPv6, which is redefined as a separate protocol that also absorbs ARP’s address resolution role (via NDP).Position of ICMP within an Ethernet Frame
Because ICMP is carried as the payload (data portion) of an IP packet, on an Ethernet frame it is placed after the Ethernet header (destination/source MAC addresses, etc.), following the IP header. Note that ICMP itself has no Ethernet header or FCS (Frame Check Sequence) of its own — it is treated purely as part of the contents of the IP packet.
The destination host uses the Ethernet header’s Type field (0x0800 = IPv4) to determine that the payload is an IP packet, and then the IP header’s Protocol field (1) to determine that its data portion is an ICMP message, before processing it as ICMP.
ICMP Packet Format
Every ICMP message begins with a common 8-byte header. The first 4 bytes follow the same format across all messages, but the structure of the following 4 bytes (Rest of Header) and the subsequent Data section varies depending on the message type (Type/Code).
| Field Name | Size | Description |
|---|---|---|
| Type | 1 byte | The message type. Echo Request (8), Echo Reply (0), Destination Unreachable (3), Time Exceeded (11), etc. |
| Code | 1 byte | A sub-type defined per Type. The same Type can have different detailed meanings depending on the Code value. |
| Checksum | 2 bytes | An error-detection checksum covering the entire ICMP message (header + data). |
| Rest of Header | 4 bytes | A field whose contents vary by message type. For Echo, it holds the Identifier and Sequence Number; for Destination Unreachable and Time Exceeded, it is unused (zero-filled). |
| Data | Variable | Data depending on the message type. For Echo, arbitrary padding data; for error messages, a portion of the original IP packet that caused the problem. |
Common ICMP Message Types
Many message types are defined for ICMP, but the ones most commonly encountered in practice are:
| Type | Name | Common Codes | Overview |
|---|---|---|---|
| 0 | Echo Reply | 0 | Response to an Echo Request (ping) |
| 3 | Destination Unreachable | 0-15 | Notification that the destination cannot be reached |
| 5 | Redirect | 0-3 | Notification that a better route (next hop) exists |
| 8 | Echo Request | 0 | Connectivity check request (ping) |
| 11 | Time Exceeded | 0, 1 | Notification that a packet was discarded, e.g. due to TTL expiry |
| 12 | Parameter Problem | 0-2 | Notification of a problem with an IP header parameter |
The full list of types and codes is maintained by IANA.
Constraints on Generating ICMP Messages (RFC 1122)
If ICMP error messages were generated without limit, it could trigger a chain reaction of errors on the network (an ICMP error itself triggering another ICMP error, and so on). To prevent this, RFC 1122 defines constraints such as:
- Do not generate a new ICMP error message in response to an ICMP error message (an error response to an ICMP query message such as Echo Reply may be an exception).
- Do not generate an ICMP error message for a second or later fragment (a packet whose fragment offset is not 0).
- As a rule, do not generate an ICMP error message for a packet whose destination is a broadcast or multicast address.
References
| RFC | Title | Overview |
|---|---|---|
| RFC 792 | Internet Control Message Protocol | The original ICMP specification, defining the basic message format and types. |
| RFC 1122 | Requirements for Internet Hosts – Communication Layers | Defines host requirements, including constraints on generating ICMP messages. |