Loading content...
In a world where IP packets travel through dozens of routers across continents with no acknowledgment, what happens when something goes wrong? When a destination doesn't exist, when a packet takes too long, when fragmentation fails, or when a router encounters malformed data—who tells the sender?
This is ICMP's primary mission: error reporting. ICMP error messages are the network's way of saying "something went wrong with your packet, and here's what happened."
Unlike transport-layer reliability mechanisms (like TCP's acknowledgments), ICMP error reporting happens at the network layer and covers problems that occur in transit—before a packet ever reaches its intended destination. These errors represent fundamental delivery failures that no amount of retransmission will fix without understanding what went wrong.
By the end of this page, you will understand how ICMP error messages are generated, the structure of error messages and what information they carry, all major error types (Destination Unreachable, Time Exceeded, Parameter Problem, Redirect), the rules governing when ICMP errors can and cannot be sent, and how to interpret error messages for troubleshooting.
Before examining specific error types, we must understand the general structure of ICMP error messages. All ICMP error messages share a common format that carries critical diagnostic information.
The ICMP Error Message Format
Every ICMP error message contains:
ICMP Header (8 bytes minimum)
Original Packet Data (minimum 28 bytes)
This "original packet data" is crucial—it allows the sender to identify exactly which packet triggered the error and why.
Why Include the Original Packet?
Including the original IP header plus 8 bytes of payload serves several critical purposes:
1. Packet Identification The original IP header contains source and destination addresses, identification field, and protocol number. This tells the sender exactly which packet failed.
2. Transport Layer Context The first 8 bytes of payload typically contain transport layer ports (for TCP/UDP), which identify the specific connection or application affected. For TCP, this includes source port, destination port, and sequence number. For UDP, it includes source and destination ports.
3. Demultiplexing Errors When the source receives an ICMP error, it can match the error to a specific socket/application by examining the original ports and protocol.
4. Debugging Information Network engineers can see exactly what packet triggered the error, enabling precise diagnosis.
The requirement to include 8 bytes of original payload was carefully chosen. For both TCP and UDP, 8 bytes captures the source port (2 bytes), destination port (2 bytes), and 4 additional bytes (sequence number for TCP, length and checksum for UDP). This is exactly enough to identify the affected connection.
The Destination Unreachable message is the most common and arguably most important ICMP error type. It indicates that a packet could not be delivered to its destination for a specific reason identified by the Code field.
A Destination Unreachable message can be generated by:
The Code field provides the specific reason, and understanding these codes is essential for network troubleshooting.
| Code | Name | Generated By | Meaning |
|---|---|---|---|
| 0 | Network Unreachable | Router | Router has no route to the destination network |
| 1 | Host Unreachable | Router/Gateway | Final-hop router cannot reach the specific host |
| 2 | Protocol Unreachable | Destination Host | IP packet's protocol field specifies unsupported protocol |
| 3 | Port Unreachable | Destination Host | UDP destination port has no listening application |
| 4 | Fragmentation Needed (DF Set) | Router | Packet too large but Don't Fragment flag is set |
| 5 | Source Route Failed | Router | Specified source route cannot be followed |
| 6 | Destination Network Unknown | Router | Network doesn't exist (config issue, not routing) |
| 7 | Destination Host Unknown | Router | Host doesn't exist (config issue) |
| 8 | Source Host Isolated | Router | Obsolete—not used |
| 9 | Network Administratively Prohibited | Router/Firewall | Firewall/ACL blocks traffic to network |
| 10 | Host Administratively Prohibited | Router/Firewall | Firewall/ACL blocks traffic to host |
| 11 | Network Unreachable for TOS | Router | Network unreachable for requested Type of Service |
| 12 | Host Unreachable for TOS | Router | Host unreachable for requested Type of Service |
| 13 | Communication Administratively Prohibited | Router/Firewall | General administrative block |
| 14 | Host Precedence Violation | Router | Precedence value not permitted |
| 15 | Precedence Cutoff in Effect | Router | Precedence below network minimum |
Most Critical Codes for Network Engineers
Code 0 - Network Unreachable Generated when a router has no route (not even a default route) to the destination network. This indicates a routing problem—the packet literally has nowhere to go. Common causes include:
Code 1 - Host Unreachable Generated by the final router (default gateway for the destination) when it cannot reach the specific host. The router knows the network exists but ARP resolution fails or the host doesn't respond. Common causes:
Code 3 - Port Unreachable Generated by the destination host when a UDP datagram arrives for a port with no listening application. TCP doesn't use this—it sends RST packets instead. This is used by traceroute (UDP mode) to detect arrival at the destination.
Code 4 - Fragmentation Needed but DF Set Critical for Path MTU Discovery. When a router cannot forward a packet because it's larger than the outgoing link's MTU, but the Don't Fragment flag is set, this message is returned. It includes the MTU of the limiting link, allowing the source to adjust packet sizes.
123456789101112131415
# Capturing ICMP Destination Unreachable messages with tcpdump $ sudo tcpdump -i eth0 'icmp[icmptype] == 3' -v # Example output - Network Unreachable (Code 0):10:23:45.123456 IP router.example.net > host.local: ICMP net 10.99.0.0 unreachable, length 56 # Example output - Host Unreachable (Code 1):10:23:46.234567 IP gateway.local > host.local: ICMP host 192.168.1.50 unreachable, length 56 # Example output - Port Unreachable (Code 3):10:23:47.345678 IP server.example.com > host.local: ICMP server.example.com udp port 12345 unreachable, length 56 # Example output - Fragmentation Needed (Code 4) - Shows MTU:10:23:48.456789 IP router.isp.net > host.local: ICMP 203.0.113.50 unreachable - need to frag (mtu 1400), length 556Type 3 Code 4 (Fragmentation Needed) is essential for Path MTU Discovery. If this message is blocked by firewalls, TCP connections will hang when large data transfers are attempted. Many 'MTU black hole' problems stem from overzealous ICMP filtering that blocks this specific code.
The Time Exceeded message is generated when a packet's Time To Live (TTL) expires during transit or when fragment reassembly takes too long. This message serves two vital functions:
The Time Exceeded message has two codes, each representing a different expiration scenario:
| Code | Name | Generated By | Meaning |
|---|---|---|---|
| 0 | TTL Exceeded in Transit | Router | TTL decremented to 0 during forwarding |
| 1 | Fragment Reassembly Time Exceeded | Destination Host | Not all fragments arrived within timeout |
Code 0 - TTL Exceeded in Transit
This is the code that makes traceroute possible. Every IP packet carries a TTL field, which is decremented by one at each router hop. When TTL reaches zero, the router:
The router includes its own IP address as the source of the ICMP message, thereby revealing itself. Traceroute exploits this by sending packets with increasing TTL values (1, 2, 3, ...), receiving Time Exceeded from each router along the path until reaching the destination.
The Purpose of TTL
TTL exists because routing loops can occur due to:
Without TTL, a packet caught in a loop would circulate forever, consuming bandwidth and potentially crashing routers as loops accumulate traffic. TTL guarantees that packets have a finite lifetime in the network—typically set between 64 and 255 hops, far more than any legitimate path requires.
Code 1 - Fragment Reassembly Time Exceeded
When an IP datagram is fragmented, the destination host must collect all fragments and reassemble the original datagram. The destination starts a reassembly timer when the first fragment arrives—typically 60-120 seconds.
If the timer expires before all fragments arrive, the host:
This prevents memory exhaustion attacks where an attacker sends first fragments of many datagrams but never completes them, attempting to exhaust victim's reassembly buffers.
Common causes of fragment reassembly timeout:
Different operating systems use different default TTL values: Linux uses 64, Windows uses 128, Cisco IOS uses 255. By examining TTL values in received packets (and accounting for hop count), you can often fingerprint the source's operating system. This is a common reconnaissance technique.
The Parameter Problem message indicates that a router or host encountered an issue with a specific field in the IP header or options. Unlike other error types that report routing or delivery problems, Parameter Problem reports protocol errors—cases where the packet itself is malformed or contains invalid values.
This message is relatively rare in well-functioning networks but becomes essential when debugging:
| Code | Name | Meaning |
|---|---|---|
| 0 | Pointer Indicates the Error | The Pointer field points to the problematic byte |
| 1 | Missing Required Option | A required IP option is not present |
| 2 | Bad Length | An option has an incorrect length field |
The Pointer Field
Parameter Problem messages include a Pointer field (8 bits) that indicates the byte position within the original IP header where the error was detected. This allows the sender to identify exactly which field is problematic.
For example:
When Parameter Problem is Generated
A router or host generates this message when:
Invalid IP Header Length (IHL): The IHL field claims more or fewer bytes than actually present, or the value is less than 5 (minimum header size)
Invalid Options: An IP option is malformed—wrong length, invalid option code, or option extends beyond header
Unsupported Features: The packet uses a feature the router cannot process, such as an unknown option type that requires special handling
Checksum Failure: While typically handled silently (packet discarded), some implementations send Parameter Problem
Inconsistent Fields: Fields contradict each other (e.g., Total Length smaller than IHL would indicate)
12345678910111213141516
# ICMP Parameter Problem Message Structure (Type 12) 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| Type=12 | Code | Checksum |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| Pointer | Unused (24 bits) |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| || Original IP Header + First 8 bytes of Original Payload || (28+ bytes) |+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ # Example: Pointer = 9 indicates error at Protocol field position# This might occur if an unknown protocol number is specifiedWhen you receive an ICMP Parameter Problem, use the Pointer value to identify the exact field causing issues. Convert the pointer to an IP header field (0-3 = Version/IHL/TOS/TotalLength, 4-7 = Identification/Flags/FragOffset, 8-11 = TTL/Protocol/Checksum, 12-15 = Source IP, 16-19 = Destination IP, 20+ = Options). This pinpoints the problem area immediately.
The ICMP Redirect message is used by routers to inform hosts of a better route. When a router receives a packet and determines that a better first-hop router exists on the same network as the sender, it forwards the packet but also sends a Redirect to the sender, saying "next time, send to this router instead."
This mechanism allows hosts to operate with minimal routing knowledge—often just a default gateway—while still achieving efficient routing over time through dynamic corrections.
How Redirect Works
Consider a scenario:
| Code | Name | Meaning |
|---|---|---|
| 0 | Redirect for Network | Better route exists for the entire network |
| 1 | Redirect for Host | Better route exists for this specific host only |
| 2 | Redirect for TOS and Network | Better route for network with specific Type of Service |
| 3 | Redirect for TOS and Host | Better route for host with specific Type of Service |
Conditions for Generating a Redirect
A router will only generate a Redirect when ALL of the following are true:
The packet arrives on the same interface as the next-hop route dictates—meaning the sender and better router are on the same subnet
The source IP is on the directly connected network—router won't redirect packets from other networks
The packet is not source-routed—if sender specified the route, don't override it
Redirects are enabled—many routers disable this for security (see below)
Security Concerns with Redirects
ICMP Redirects present significant security risks:
For these reasons, most modern operating systems and routers ignore or disable ICMP Redirects by default. Enterprise networks typically configure hosts statically or use proper routing protocols rather than relying on Redirects.
Disable acceptance of ICMP Redirects on all production systems. On Linux: net.ipv4.conf.all.accept_redirects=0, net.ipv4.conf.all.send_redirects=0. On Windows: via registry or netsh. Proper routing configuration eliminates any need for Redirects while removing their security risks.
Source Quench was ICMP's congestion notification mechanism. When a router experienced buffer overflows due to congestion, it could send Source Quench messages to senders, requesting they slow down.
This message has been officially deprecated by RFC 6633 (May 2012).
Why Source Quench Failed
Source Quench had fundamental design flaws that made it ineffective for congestion control:
Modern Congestion Control
Congestion control has moved away from ICMP to more sophisticated mechanisms:
TCP Congestion Control: TCP's Additive Increase Multiplicative Decrease (AIMD) algorithm, combined with techniques like Fast Retransmit and Fast Recovery, handles congestion without any ICMP involvement. TCP infers congestion from packet loss or ECN marks.
Explicit Congestion Notification (ECN): Routers can mark packets with ECN bits rather than dropping them. Receivers echo this congestion signal to senders, who reduce their rate. This works without generating additional packets.
Active Queue Management (AQM): Algorithms like RED (Random Early Detection) and CoDel drop packets strategically before queues overflow, signaling congestion to TCP senders through the existing loss detection mechanism.
What to Do with Source Quench Today
While Source Quench is deprecated, understanding its failure is instructive. It demonstrates that network-layer congestion signaling is problematic and why modern approaches operate at the transport layer (TCP) or through in-band signaling (ECN). This lesson shaped the design of QUIC and other modern protocols.
ICMP error messages are powerful diagnostic tools, but uncontrolled generation could flood networks or create attack amplification vectors. RFC 1122 and RFC 792 specify strict rules about when ICMP errors may and may NOT be generated.
The Core Rules
These rules prevent ICMP storms and protocol loops:
Understanding the "No Errors for Errors" Rule
This rule is critical for preventing cascading failures. Consider without it:
The rule ensures that at most one ICMP error is generated per original packet, regardless of how many routers encounter problems with the error message itself.
Understanding the "First Fragment Only" Rule
When IP fragments a datagram, only the first fragment contains the transport layer header (ports, etc.). Subsequent fragments contain only data. Since ICMP errors include "the first 8 bytes of original payload" for demultiplexing, errors for non-first fragments would be useless—they wouldn't contain port information to identify the connection.
| Original Packet Type | Generate ICMP Error? | Rationale |
|---|---|---|
| Regular unicast packet | YES | Standard error reporting |
| ICMP error message | NO | Prevents error loops |
| ICMP query (Echo, etc.) | MAYBE | Some errors may be appropriate |
| Broadcast destination | NO | Prevents amplification |
| Multicast destination | NO | Prevents amplification |
| First fragment | YES | Contains port info for debugging |
| Non-first fragment | NO | No port info to include |
| 0.0.0.0 source address | NO | No valid destination for error |
| Loopback source (127.x.x.x) | NO | Shouldn't appear on network |
Beyond these rules, most implementations apply rate limiting to ICMP error generation—typically 1-10 errors per second per destination. This prevents CPU exhaustion under attack and limits amplification. This is a practical necessity not specified in the original RFCs but universally implemented.
ICMP error reporting transforms IP from a silent best-effort service into a network with observable failure modes. We've explored the structure, types, and rules governing these essential diagnostic messages:
What's Next
We've covered ICMP's error reporting function in depth. However, ICMP also supports proactive diagnostic queries—messages where a host actively requests information rather than reactively receiving error reports. The next page explores ICMP query messages, including the Echo Request/Reply pair that powers ping, timestamp queries, and other diagnostic tools.
You now understand how ICMP reports errors when packets cannot be delivered. You can identify error types, interpret codes and pointer values, and explain the rules preventing ICMP storms. Next, we'll explore ICMP query messages—the active diagnostic tools like ping that every network engineer uses daily.