What ICMP is
ICMP (Internet Control Message Protocol) is a helper protocol at the Internet layer. Routers and hosts use it to send status and error messages: "your packet could not be delivered", "TTL expired", "are you there?". It never carries application data.
Unlike TCP and UDP, ICMP has no ports. It rides directly inside an IP packet. Compare the two envelopes:
TCP packet
Common ICMP messages
Every ICMP message has a type (what kind of message) and a code (more detail):
| Type | Name | Codes worth knowing | Used by |
|---|---|---|---|
| 8 | Echo Request | 0 | ping: "are you there?" |
| 0 | Echo Reply | 0 | ping: "yes" |
| 11 | Time Exceeded | 0 = TTL reached 0 in transit | Loops (chapter 12), traceroute |
| 3 | Destination Unreachable | 0 = no route to network · 1 = host unreachable · 3 = port unreachable · 4 = packet too big (section 8) | Routers and hosts reporting failure |
| 5 | Redirect | 1 = better next hop for this host | A router suggesting a better gateway on the same LAN (usually ignored today) |
ping
ping sends an Echo Request and waits for an Echo Reply. If the reply comes back, the host is up and reachable. The time between sending and receiving is the RTT (round-trip time): how you measure latency.
Wide by design - scroll it sideways.
Pinging kade-api from home:
$ ping -c 4 api.kade.lk PING api.kade.lk (34.87.120.15): 56 data bytes 64 bytes from 34.87.120.15: icmp_seq=0 ttl=57 time=41.2 ms 64 bytes from 34.87.120.15: icmp_seq=1 ttl=57 time=40.8 ms 64 bytes from 34.87.120.15: icmp_seq=2 ttl=57 time=42.0 ms 64 bytes from 34.87.120.15: icmp_seq=3 ttl=57 time=41.3 ms --- api.kade.lk ping statistics --- 4 packets transmitted, 4 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 40.8/41.3/42.0/0.4 ms
| Part | Meaning |
|---|---|
| (34.87.120.15) | DNS ran first (chapter 1). ping works on IPs. |
| icmp_seq=0,1,2… | Each request's number. A missing number = a lost packet. |
| ttl=57 | The reply's TTL on arrival. kade-api (Linux) starts at 64, so the reply passed about 64 − 57 = 7 routers. |
| time=41.2 ms | RTT. Colombo to Singapore and back; most of it is distance (section 6). |
| 0.0% packet loss | Any steady loss means a problem on the path. |
| stddev = 0.4 ms | How much the RTT jumps around (jitter). Matters for calls and games. |
Time Exceeded: the key to traceroute
Recall from chapter 12: every router lowers a packet's TTL by 1. When it reaches 0, the router drops the packet and sends an ICMP Time Exceeded message back to the sender. That message comes from the router, so its source IP tells the sender exactly which router the packet died at.
How traceroute works
traceroute uses this on purpose. It sends a probe with TTL=1: the first router lowers it to 0 and replies with Time Exceeded, revealing hop 1. Then TTL=2 reveals hop 2, TTL=3 reveals hop 3, and so on until the destination itself answers. Run it from the office front desk PC, along chapter 12's path. Press the button to send each probe:
- Front desk PCsender
- R1 office172.16.1.1
- R2 ISP edge198.51.100.1
- R3 ISP border10.200.0.2
- R4 Google edge192.0.2.2
- Google routersilent
- kade-api34.87.120.15
Press the button to send the first probe, with TTL = 1.
traceroute to api.kade.lk (34.87.120.15), 64 hops max
| Tool | Probe sent | How the destination answers |
|---|---|---|
| traceroutemacOS, Linux default | UDP to high ports (33434 and up) | ICMP Destination Unreachable, code 3 (port unreachable) |
| tracertWindows · traceroute -I | ICMP Echo Request | ICMP Echo Reply |
| traceroute -T -p 443Linux, needs sudo | TCP to port 443 | A TCP reply, since the port is open |
Reading traceroute output
$ traceroute api.kade.lk traceroute to api.kade.lk (34.87.120.15), 64 hops max 1 172.16.1.1 0.9 ms 0.8 ms 1.0 ms 2 198.51.100.1 5.8 ms 6.1 ms 5.9 ms 3 10.200.0.2 7.1 ms 7.3 ms 7.0 ms 4 192.0.2.2 36.4 ms 36.2 ms 36.8 ms 5 * * * 6 34.87.120.15 37.2 ms 37.0 ms 37.5 ms
| # | You see | It means |
|---|---|---|
| 1 | Three times per line | traceroute sends 3 probes per TTL. Each time is the RTT to that router. |
| 3 | A private IP (10.200.0.2) in the middle | An ISP's internal link. Normal. |
| 4 | A jump from 7 ms to 36 ms | The link from Colombo to Singapore. A jump that stays for every later hop is distance or a slow link at that point. |
| 5 | * * * | No answer within the time limit. Often a router that does not send Time Exceeded, or limits how many it sends. If later hops answer, the path is fine. |
| - | Stars from some hop to the end | Traffic really is stopped there, or the destination's firewall blocks the probe type (section 5). |
| - | One hop slow, the next ones fast | That router is just slow to answer ICMP (low priority). Not a real problem. |
mtr combines both tools: it runs traceroute continuously and shows loss and latency per hop, which makes a flaky hop much easier to spot than a single run.
Destination Unreachable
Type 3 tells the sender its packet went nowhere, and the code says why:
| Code | Sent by | Kadé example |
|---|---|---|
| 0 network | A router with no route for the destination | R1 loses its default route: every internet destination fails at once |
| 1 host | The last router: ARP for the host got no answer | The office printer is switched off |
| 3 port | The host itself: nothing listens on that UDP port | What traceroute's last hop sends (section 5) |
| 4 too big | A router: packet too big for the next link, and "don't fragment" is set | Section 8 |
Packet too big: path MTU discovery
Chapter 1 set the MTU at 1,500 bytes. Some links carry less: VPN tunnels add their own headers, and GCP VPCs use an MTU of 1,460 by default. When a big packet reaches a smaller link, IP could split it into pieces (fragmentation), but TCP packets are normally marked "don't fragment". So the router drops it and replies ICMP type 3, code 4: "too big, the limit here is N". The sender then uses smaller packets. This is path MTU discovery.
| 1 | Office PC sends a 1,500-byte packet, "don't fragment" set, toward kade-db over the future VPN. |
| 2 | The VPN link carries at most 1,400. The router drops it and sends ICMP 3/4: MTU 1,400. |
| 3 | The PC resends in 1,400-byte packets. Everything works. |
| ! | If a firewall blocks all ICMP, step 2's message never arrives. Small requests work, but big responses hang forever. This is called a PMTU black hole, and it is very confusing to debug. |
ICMP and firewalls
Because ICMP has no ports, firewalls treat it as its own protocol, allowed or blocked as a whole or by type. Some networks block ping so their hosts are harder to discover. That is fine, but blocking all ICMP breaks section 8 and makes debugging much harder.
For kade-vpc, allow ping only from Kadé's own public IPs (the home and office NAT addresses from chapter 10):
gcloud compute firewall-rules create kade-allow-icmp \ --network=kade-vpc --direction=INGRESS --allow=icmp \ --source-ranges=203.0.113.45/32,198.51.100.20/32Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | ICMP | Internet-layer status and error messages; no ports, no app data | ICMP, IP protocol number |
| 2 | Messages | Type + code: Echo (8/0), Time Exceeded (11), Unreachable (3), Redirect (5) | type, code |
| 3 | ping | Echo Request/Reply; RTT, loss, jitter; reply TTL hints at hop count | RTT, jitter, packet loss |
| 5 | traceroute | TTL 1, 2, 3 … each router answers Time Exceeded | traceroute, probe |
| 6 | Reading it | Jumps that stay = real; lone stars = often fine; path is one-way | mtr |
| 8 | Too big | ICMP 3/4 drives path MTU discovery; block it and big transfers hang | fragmentation, PMTUD, black hole |
| 9 | Firewalls | Treat ICMP by type; allow errors back in |
Try it yourself
Reachability and RTT
- What to look for: time, ttl, loss.
- Runs on: Windows: ping -n 4 1.1.1.1
- From section: 3. ping
ping -c 4 1.1.1.1A ping with TTL=1
- What to look for: "Time to live exceeded" from your gateway: traceroute's trick by hand.
- Runs on: macOS · Linux: ping -c 1 -t 1 · Windows: ping -n 1 -i 1
- From section: 4. Time Exceeded: the key to traceroute
ping -c 1 -m 1 1.1.1.1Every router on the way
- What to look for: Hop 1 is your gateway; watch for jumps that stay.
- Runs on: Windows: tracert 1.1.1.1
- From section: 5. How traceroute works
traceroute 1.1.1.1Same path, different probes
- What to look for: Differences in the last hops show what firewalls allow.
- Runs on: ICMP mode · Linux TCP mode: sudo traceroute -T -p 443 1.1.1.1
- From section: 5. How traceroute works
traceroute -I 1.1.1.1Live traceroute with loss per hop
- What to look for: Loss that starts at one hop and stays for all later ones.
- Runs on: install mtr
- From section: 6. Reading traceroute output
mtr 1.1.1.1Largest packet that fits
- What to look for: 1472 + 8 + 20 = 1500 works; 1473 gives "message too long".
- Runs on: macOS · Linux: ping -M do -s 1472
- From section: 8. Packet too big: path MTU discovery
ping -D -s 1472 1.1.1.1ICMP messages live
- What to look for: "echo request", "echo reply", "time exceeded in-transit".
- From section: 2. Common ICMP messages
sudo tcpdump -n -i en0 icmp