I’ve went through RFC 792 and would like to share some basic (high level) info about ICMP and how we are using it.

ICMP is the Internet Control Message Protocol :

  • runs over the network layer, so it’s encapsulated in IP datagrams
  • unreliable, simple datagram service, no retransmission if a message doesn’t reach the destination
  • an ICMP message takes the IP header of the original datagram plus the first 8 bytes of its payload, then gets marked with a type and code. Types and codes are in RFC 792 and the IANA registry
  • host unreachable - the datagram reaches the last router, but that router doesn’t know where the host is
  • port unreachable - the port in the packet isn’t recognized on the receiver’s side

How ping uses ICMP :

The ping application calls ICMP directly. It sends an echo request (type 8 code 0), which gets encapsulated into an IP datagram and flows through the network. When the receiver gets it, it sends back an echo reply (type 0 code 0).

How traceroute uses ICMP and UDP (*nix version, Windows tracert uses ICMP echo requests only) :

  • the goal is to discover all routers in the path and show the round trip delay to each
  • traceroute sends a UDP message with TTL 1
  • the first router decrements TTL to 0, drops the packet and sends back ICMP type 11 (TTL expired), built from the IP header and the first 8 bytes of the payload
  • when that message arrives, traceroute knows the first hop and measures the round trip time
  • next UDP message goes out with TTL 2, then 3 and so on
  • traceroute uses a random unused UDP port, so when the packet finally reaches the destination, the receiver answers with ICMP type 3 code 3 (port unreachable) and the trace ends