ELEC3506

Network LayerLecture 515 min

ICMP — Ping and Traceroute

How ICMP reports what IPv4 itself stays silent about, and how ping and traceroute build on two different message types to do it.

By the end of this page you should be able to

  • Explain why ICMP exists given that IPv4 has no error reporting of its own
  • Distinguish ICMP's error messages from its query messages
  • Trace the ping procedure step by step
  • Trace how traceroute uses TTL and Time Exceeded to map an entire route

The idea

IPv4 makes no promises. Lecture 5 is direct about this: the protocol has no error reporting or correction mechanism built in at all — if a datagram is lost, malformed, or cannot be delivered, IP itself says nothing. ICMP is what fills that silence. Every TCP/IP host implements it, and its whole job is reporting when something unexpected has happened.

Two everyday tools are built entirely on top of it. Ping asks a single direct question — is this host there? Traceroute asks a more elaborate one, by deliberately provoking an error from every router along the way to map the whole route.

How it works

Two categories of message

MessageCategoryPurpose
Echo RequestQueryPing's outbound message
Echo ReplyQueryPing's response, confirming reachability
Time ExceededErrorSent when a datagram's TTL reaches 0
Destination UnreachableErrorSent when a packet cannot reach its destination
Query messages are a deliberate question and its answer. Error messages report a fault the sender did not ask for.

Worked example

Ping

  1. Send an ICMP Echo Request to the target host.

  2. Wait for an ICMP Echo Reply.

  3. If the reply arrives, the host is reachable. That is the entire test — ping confirms reachability, nothing about the path taken to get there.

  4. If it times out instead, the host is treated as unreachable, and a Destination Unreachable message is returned.

AnswerEcho Request out, Echo Reply back — or a timeout and Destination Unreachable

Worked example

Traceroute

  1. Send an IP packet to the destination with TTL set to 1.

  2. The first router along the path decrements TTL to 0, discards the packet, and returns a Time Exceeded message — which reveals that router’s address.

  3. Send another packet, this time with TTL set to 2.

  4. The second router’s TTL now hits 0 instead, revealing its address the same way.

  5. Repeat with TTL = 3, 4, 5, and so on, one router discovered per step.

  6. Eventually a packet’s TTL survives long enough to reach the destination itself, and the address of every router on the route has been learned along the way.

AnswerTTL = 1, 2, 3... — one router revealed per Time Exceeded reply, until the destination answers

Aside

Try the lecture’s own two exercises on a real machine: ping www.yahoo.com and tracert www.yahoo.com (or traceroute / trace, depending on the OS). Ping gives an average, minimum and maximum round-trip time; traceroute prints the router-by-router path this page’s worked example describes.

Where marks get lost

Ping and traceroute are not the same mechanism

It is tempting to think of traceroute as “ping, but it also shows the route.” It doesn’t work that way. Ping is a single end-to-end Echo Request/Reply pair — nothing in between ever responds. Traceroute never expects an Echo Reply at all; it deliberately manufactures a Time Exceeded error from every intermediate router by exhausting TTL one value at a time, and only succeeds in reaching the destination on the final attempt. Confusing which message type belongs to which tool is an easy way to lose a mark on a question that asks you to explain either one.

Aside

The slides do not give the ICMP header format, its field widths, or the specific numeric codes attached to each message type — only the message names and what triggers them. If a question needs the header layout or a specific code number, that content is not in this lecture; check the tutorial or the recording before relying on a number from anywhere else.

In the exam

  • Error vs query is the core distinction. Time Exceeded and Destination Unreachable report a fault; Echo Request and Echo Reply are a deliberate exchange.
  • Traceroute’s mechanism is TTL exhaustion, one hop at a time — TTL = 1, 2, 3… — reading the source address off each Time Exceeded reply. Be ready to state which router replies for a given TTL value.
  • Ping only proves reachability, not the path. Do not describe it as discovering routers.
  • No ICMP header format is given in this lecture. Say so rather than guessing at field widths if a question pushes past what was covered.
  • Know the two named commandsping and tracert/traceroute — as the practical tools behind both procedures.

Check yourself

  1. Which pair correctly matches an ICMP message to its category?
  2. Traceroute sends a packet with TTL set to 3. Which router replies with a Time Exceeded message?
  3. A ping's Echo Request receives no reply and the packet times out. What does the sender get instead?
  4. What is traceroute actually testing that ping is not?