Sub topic 2
ICMP: the protocol behind ping and traceroute
This chapter assumes you know what an IP address is, can open a command prompt or terminal, and know that routers forward packets between networks. It explains the protocol that ping and traceroute use, so their output makes sense later.
What ICMP is
The Internet Control Message Protocol (ICMP) is a companion to IP. It carries error reports and simple diagnostic messages between hosts and routers. IP itself has no way to say "I could not deliver your packet." ICMP fills that gap.
ICMP messages travel inside IP packets, with IP protocol number 1 (IPv6 uses ICMPv6, protocol number 58). ICMP is not TCP or UDP. It has no ports, so you will not see "port 80" or "port 53" in an ICMP exchange. A message is identified by a type number and a code number.
Echo request and echo reply
Ping uses two message types:
- Echo request (ICMP type 8 in IPv4) asks "are you there?"
- Echo reply (type 0) answers it.
When you run ping 8.8.8.8, your computer sends an echo request containing a small block of data, an identifier, and a sequence number. The target copies the data into an echo reply and sends it back. Your computer matches the reply to the request using the identifier and sequence number, then computes the round-trip time (RTT), which is the time between sending and receiving.
Error messages
Routers and hosts also use ICMP to report problems. Two of these matter for the tools in this tutorial.
| Message | Type (IPv4) | Meaning |
|---|---|---|
| Destination Unreachable | 3 | The packet could not be delivered. The code says why, for example network unreachable, host unreachable, or fragmentation needed. |
| Time Exceeded | 11 | The packet's TTL reached zero before arriving. |
When ping shows "Destination host unreachable", a router or your own computer has sent a Destination Unreachable message. That is different from "Request timed out", where nothing came back at all. The next chapters cover how to read each case.
Time Exceeded is the basis of traceroute. Every IP packet carries a Time To Live (TTL) value. Each router decreases it by one, and a router that drops it to zero discards the packet and sends a Time Exceeded message to the sender. Traceroute sends packets with TTL 1, 2, 3 and so on, and records which router replies at each step. A later chapter covers TTL in detail.
Common misunderstandings
- ICMP is not guaranteed. Like IP, it is best effort. A missing reply does not prove the target is down.
- Ping tests only part of the path. A successful ping shows that IP packets and ICMP got through in both directions. It does not show that a web server or any TCP service works.
- Firewalls often filter ICMP. Many hosts and networks drop echo requests, or limit how fast they answer. A silent host may still be working. The chapter on misleading results returns to this.
Seeing ICMP yourself
You can confirm that ping sends no port numbers by watching it in a packet capture tool such as Wireshark with the display filter icmp. Each request and reply appears as a separate packet, with the type, code, identifier, and sequence number visible.
Exercise
A router discards your packet because its TTL reached zero. Which ICMP message does it send back to you, and which tool relies on this behavior?
Show answer
It sends a Time Exceeded message (type 11 in IPv4). Traceroute (tracert on Windows) relies on it: by raising the TTL one step at a time, it learns the address of each router on the path.
Exercise
Why does an ICMP echo exchange have no port number, and what identifies a message instead?
Show answer
ICMP is its own IP protocol (number 1 for IPv4), not TCP or UDP, so it has no ports. A message is identified by its type and code, and echo messages also carry an identifier and sequence number that match replies to requests.