Computer Networking › Section E · The network layer: control plane › Topic E.5
ICMP
IP is best effort and silent about its failures, so the network needs a way to say "that destination is unreachable" or "your packet died here". The Internet Control Message Protocol carries those reports, and ping and traceroute are built on it.
What ICMP is for
The Internet Control Message Protocol (ICMP), defined for IPv4 in RFC 792, lets hosts and routers exchange network-layer information. Its most common use is error reporting: when a router cannot deliver a datagram, it can send an ICMP message back to the source explaining why. It also carries queries, such as the echo request that ping sends. ICMP is usually described as part of IP, yet architecturally it sits just above it: ICMP messages travel as the payload of IP datagrams, with protocol number 1, exactly as TCP segments travel with protocol number 6. A receiving host hands any datagram with protocol 1 to its ICMP code.
Message format: type, code and evidence
Every ICMP message starts with an 8-bit type and an 8-bit code, followed by a checksum. The type gives the broad category, such as destination unreachable or time exceeded, and the code refines it. An error message also carries the IP header of the datagram that caused the problem plus the first 8 bytes of that datagram's payload. Those 8 bytes are chosen with care: they include the source and destination port numbers of a TCP or UDP segment, so the sending host can work out which connection or application the error belongs to. ICMP never sends an error about another ICMP error message, which prevents storms of errors.
Common message types
Some widely used IPv4 types: type 0, echo reply, and type 8, echo request, used by ping. Type 3, destination unreachable, has several codes: 0 network unreachable, 1 host unreachable, 2 protocol unreachable, 3 port unreachable, and 4 fragmentation needed but the don't-fragment flag is set. Type 11, time exceeded, with code 0 meaning the TTL reached zero in transit. Type 12 reports a bad IP header. Type 4, source quench, was meant to let congested routers slow senders down; it was rarely used and has been formally deprecated, since TCP congestion control and Explicit Congestion Notification handle that job.
Ping
The ping program sends ICMP echo requests, type 8 code 0, to a host. A host that receives one returns an echo reply, type 0 code 0, with the same identifier, sequence number and data. In most systems the operating system itself answers, so no server program is needed. By timing each request and reply, ping reports round-trip times and the fraction of probes lost. A failed ping does not prove a host is down, though: many firewalls and servers block or rate-limit echo requests, and routers may give ICMP low priority when busy, which can make delays look worse than the real forwarding delay.
How traceroute uses ICMP
Traceroute discovers the routers on a path. As the Computer Science topic Internet protocols: layers, TCP, and UDP showed, it sends probes with TTL 1, 2, 3 and so on. In the classic Unix version, each probe is a UDP datagram to an unlikely port number. The router where a probe's TTL reaches zero discards it and returns ICMP time exceeded, type 11 code 0, which reveals that router's address; the source times the round trip. Eventually a probe reaches the destination, whose UDP layer finds no application on that port and returns ICMP port unreachable, type 3 code 3. That different reply tells traceroute to stop. Usually three probes are sent for each TTL.
Worked example: reading a traceroute
A trace towards a server shows: TTL 1, 192.168.1.1, about 2 ms; TTL 2, 100.64.0.1, 9 ms; TTL 3, 198.51.100.1, 11 ms; TTL 4, three asterisks; TTL 5, 203.0.113.9, 48 ms, port unreachable. 1. Hop 1 is the home router, and hop 2 an address in the carrier-grade NAT block, so the ISP shares public addresses. 2. The rise from 11 to 48 ms between hops 3 and 5 suggests a long link, perhaps a cross-country one. 3. The asterisks mean hop 4 sent no time exceeded reply in time, often because it filters or rate-limits ICMP; traffic still crossed it. 4. The port unreachable reply marks the destination. Check: the server is 5 hops away, so 4 routers lie between.
Path MTU discovery
IPv4 fragmentation is costly, as IPv4 datagrams and addressing explained, so hosts try to learn the smallest MTU on a path and send datagrams that fit. In path MTU discovery the source sets the don't-fragment flag. A router whose next link is too small for such a datagram drops it and returns destination unreachable, type 3 code 4, fragmentation needed, including the next link's MTU. The source lowers its datagram size and tries again. IPv6 routers never fragment, so ICMPv6 has a dedicated Packet Too Big message for the same purpose. A network that blocks all ICMP breaks this mechanism, creating a black hole where large packets silently vanish.
Worked example: discovering a smaller MTU
A host sends TCP segments in 1,500-byte IPv4 datagrams with don't-fragment set. One link on the path, a tunnel, has an MTU of 1,400 bytes. 1. The router before the tunnel drops the first 1,500-byte datagram. 2. It sends ICMP type 3 code 4 back to the host, reporting a next-hop MTU of 1,400. 3. The host records 1,400 bytes as the path MTU for that destination. 4. With 20-byte IP and 20-byte TCP headers, each segment can now carry \(1400 - 20 - 20 = 1360\) bytes of data, and the lost data is retransmitted in smaller segments. Check: had a firewall dropped the ICMP message, the host would keep resending 1,500-byte datagrams that never arrive.
ICMPv6
IPv6 has its own version, ICMPv6, carried with next-header value 58. It keeps the familiar jobs, with renumbered types: destination unreachable, Packet Too Big, time exceeded, and echo request and reply. It also takes on duties that IPv4 handled with other protocols. Neighbor Discovery uses ICMPv6 messages to find routers (router solicitation and router advertisement, the basis of the SLAAC autoconfiguration described in IPv6) and to learn a neighbour's link-layer address (neighbour solicitation and advertisement), replacing IPv4's ARP. Multicast group membership is reported through ICMPv6 too. In IPv6, blocking ICMP is therefore even more damaging than in IPv4.
Common mistakes to avoid
First, saying ICMP runs over TCP or UDP; it rides directly in IP datagrams with protocol number 1. Second, mixing up echo request (type 8) and echo reply (type 0). Third, treating a missing ping reply or a row of asterisks in traceroute as proof that a host or router is down; it may just filter ICMP. Fourth, thinking traceroute's final reply is time exceeded; the destination answers port unreachable. Fifth, blocking all ICMP at a firewall, which breaks path MTU discovery. Sixth, forgetting that ICMPv6 replaces ARP through Neighbor Discovery.
Key takeaways
ICMP (RFC 792) carries error reports and queries between hosts and routers, inside IP datagrams with protocol number 1. Each message has a type and a code, and errors quote the offending datagram's IP header and first 8 bytes. Key types: 0 and 8 echo reply and request (ping); 3 destination unreachable, with code 3 port unreachable and code 4 fragmentation needed; 11 time exceeded. Traceroute raises the TTL one hop at a time and stops at port unreachable. Path MTU discovery relies on fragmentation-needed or Packet Too Big messages. ICMPv6 adds Neighbor Discovery, replacing ARP and supporting SLAAC.
Flashcards
Flashcard
Internet Control Message Protocol: error reports and queries
Test your understanding
Question 1 of 5
How are ICMP messages carried across a network?
Question 2 of 5
What ICMP message makes classic traceroute stop sending probes?
Question 3 of 5
A path's smallest MTU is 1,400 bytes. After path MTU discovery, how many bytes of TCP data fit in each IPv4 datagram, with 20-byte IP and TCP headers?
Question 4 of 5
A traceroute shows three asterisks at hop 6, but hops 7 to 10 reply normally. What is the most likely explanation?
Question 5 of 5
Why does blocking all ICMP at a firewall cause trouble?
