Wiki DE Start in the browser

Wiki › Protocols

ICMP, ping and traceroute

Echo request and reply, “destination unreachable” and “TTL expired”: how ping and traceroute work.

Layer
3 (Vermittlung)
Standard
RFC 792, RFC 4443, RFC 1191 …
See an example
2 demos

Messages

ICMP (Internet Control Message Protocol) carries control and error messages in IP packets (protocol 1). The most important ones:

TypeNamewhen
8 / 0echo request / replyping
3destination unreachableno route to the network, host unreachable, port closed
11time exceededthe TTL dropped to 0 on the way

The ICMP header

ICMP sits directly in the IP packet (protocol 1). The first 4 bytes are the same for all messages; what follows depends on the type. For ping it is identifier and sequence number.

ICMPMessage · RFC 792
0481216202428
Type8 bits8
Code8 bits0
Checksum16 bits0x4d5a
Identifier16 bits0x0001
Sequence number16 bits1
Datavariable32 Byte
Each row has 32 bits (4 bytes), bit 0 on the left, as the RFCs draw their headers. Dashed: variable or optional. Point at a field for an explanation.
FieldLengthExample valueMeaning
Type8 bits88 echo request, 0 echo reply, 3 destination unreachable, 11 time exceeded.
Code8 bits0More precise reason, e.g. for type 3: 0 net, 1 host, 3 port unreachable.
Checksum16 bits (2 bytes)0x4d5aChecksum over the whole ICMP message (RFC 1071).
Identifier16 bits (2 bytes)0x0001For echo: identifier of the ping program, the reply carries the same. Other types use these 4 bytes differently.
Sequence number16 bits (2 bytes)1For echo: counts the pings 1, 2, 3 …
Datavariable32 ByteArbitrary data returned by the reply (Windows: 32 bytes). For error messages, the start of the packet that caused it.
Values: Real frame from the demo “Router on a stick” (no. 7, 82 bytes), exactly as the packet list in leyoNET shows it.

Ping

ping 192.168.2.10 sends four echo requests. Every reply shows the time and the TTL of the reply packet; from the TTL you can estimate how many routers lie in between. “Request timed out” means: no reply, but no error message either, often a missing return path.

The options are named as on Windows (and -c as on Linux):

OptionEffect
-tcontinuous ping until Ctrl+C; you see live when a connection drops and comes back
-n 10 or -c 10ten instead of four requests
-i 1choose the TTL of the request yourself (1 to 255)

What happens at TTL 0?

Every router decreases the TTL by 1 before it forwards. If it becomes 0, the router drops the packet and sends “TTL expired” (type 11) to the sender. So a packet with TTL 0 never travels over a link. Try it with a target behind two routers: ping -i 1 is answered by the first router, ping -i 2 by the second, ping -i 3 arrives.

Traceroute

tracert (Windows) uses the TTL cleverly: the first packet has TTL 1 and is already dropped by the first router, which sends back “TTL expired”. The second has TTL 2, and so on. This way every router on the path reports.

C:\> tracert 192.168.3.10
  1  192.168.1.1
  2  10.0.0.2
  3  192.168.3.10

For IPv6 there is ICMPv6 with the same tasks plus neighbor discovery (IPv6).

MTU and path MTU discovery

Every link has an MTU (maximum transmission unit), 1500 bytes for the IP packet on Ethernet. If a packet is larger than the MTU of the next link, there are two ways:

  • IPv4 may fragment on the way, unless the DF bit (don't fragment) is set. Then the router drops the packet and reports destination unreachable, fragmentation needed with the right MTU back (RFC 1191).
  • IPv6 never fragments on the way. The router reports packet too big (ICMPv6 type 2, RFC 4443), and the sender makes its packets smaller (path MTU discovery, RFC 8201). Every IPv6 link must carry at least 1280 bytes (RFC 8200, Section 5).

If a firewall blocks these ICMP messages, large packets simply get stuck while small ones (like a ping) get through: a hard-to-find fault. That is why ICMP should never be blocked across the board.

See an example

  • Demo “ARP and ping in the LAN” in leyoNETDemo “ARP and ping in the LAN” in leyoNET
    Slow motion This is how it looks in the simulation: every dot is a frame on the cable.
    ARP and ping in the LAN

    Three computers on a switch, all in 192.168.1.0/24.

    PC 1 asks for PC 2's MAC with an ARP broadcast, then four ICMP echoes follow. The switch learns its MAC table.

    Watch live Project file

  • Demo “Default gateway” in leyoNETDemo “Default gateway” in leyoNET
    Slow motion This is how it looks in the simulation: every dot is a frame on the cable.
    Default gateway

    Two subnets connected by a router.

    PC 1 sees that the target is in another network and sends the packet to its router. The TTL drops by one.

    Watch live Project file

“Watch live” opens the network in leyoNET, the simulation runs in a loop. In the app you find it under File → Demo networks, with a step-by-step tour.

Practise

  • ★★☆☆☆ Protocol analysis – Task 1: ICMP and TTL · 10 goals · Worksheet (German)
  • ★★☆☆☆ Two networks with a router · 4 goals · Worksheet (German)

In leyoNET under Tools → Exercise catalogue. Every exercise checks itself.

What leyoNET simplifies

ProtocolLayerSimplification in the simulation
ICMP3Echo, destination unreachable, time exceeded
ICMPv6, Neighbor Discovery3Echo, destination unreachable, time exceeded; neighbor and router solicitation/advertisement instead of ARP; no MLD (multicast groups without registration), no redirect; router advertisements every 30 s

Standards

  • RFC 792 – Internet Control Message Protocol
  • RFC 4443 – Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification
  • RFC 1191 – Path MTU Discovery
  • RFC 8201 – Path MTU Discovery for IP version 6
  • RFC 8200 – Internet Protocol, Version 6 (IPv6) Specification

Read on

Found a mistake or have an idea? Source of this page on GitHub.