ICMP and ICMPv6
The Internet Control Message Protocol carries error and diagnostic messages for IP: ping, traceroute, unreachable and 'packet too big'. In IPv6 it also does neighbour discovery.
- OSI layer
- 3 Network
- Carried in
- IPv4 / IPv6
- Identified by
- IP protocol 1 (ICMPv6: next header 58)
- Wireshark filter
icmp || icmpv6- Encrypted
- no
Packet structure
Select a field to see what it does.
ICMP rides inside IP like a transport protocol but belongs to layer 3: it reports on IP itself. There are no ports; Type and Code say what the message is.
How it works
Ping: echo request (type 8) and echo reply (type 0) with matching Identifier and Sequence. Many hosts (Windows firewall by default) do not answer.
Errors: routers and hosts send ICMP back to the source when a packet cannot be delivered. The error contains the IP header and first 8 bytes of the original packet, enough to see the ports, so the sender can match it to a connection.
Traceroute uses TTL expiry:
sequenceDiagram
participant H as Host
participant R1 as Router 1
participant R2 as Router 2
participant T as Target
H->>R1: probe, TTL 1
R1-->>H: ICMP 11/0 time exceeded
H->>R2: probe, TTL 2 (via R1)
R2-->>H: ICMP 11/0 time exceeded
H->>T: probe, TTL 3
T-->>H: echo reply (Windows tracert) or ICMP 3/3 port unreachable (Linux UDP traceroute)
Path MTU Discovery: with DF set, a router that cannot forward a packet sends type 3 code 4 (IPv6: type 2 “packet too big”) with the MTU. Firewalls that drop all ICMP break this and cause hanging connections (large packets disappear, small ones work).
| ICMPv6 type | Purpose |
|---|---|
| 1, 2, 3, 4 | Unreachable, packet too big, time exceeded, parameter problem |
| 128, 129 | Echo request, reply |
| 133, 134 | Router Solicitation, Router Advertisement |
| 135, 136 | Neighbor Solicitation, Advertisement (replaces ARP) |
| 137 | Redirect |
| 143 | MLDv2 report (multicast group membership) |
In Wireshark
| Filter | Shows |
|---|---|
icmp || icmpv6 | All ICMP |
icmp.type == 8 || icmp.type == 0 | Ping |
icmp.type == 3 | Unreachables; add && icmp.code == 3 for closed UDP ports |
icmp.type == 3 && icmp.code == 4 | Fragmentation needed (PMTUD) |
icmp.type == 11 | TTL exceeded (traceroute, routing loops) |
icmp.type == 5 | Redirects (suspicious on most networks) |
icmp.resp_not_found | Requests without a reply |
data.len > 64 && icmp | Big ICMP payloads (tunnels, exfiltration) |
What normal looks like: small echo payloads with standard patterns (56 bytes on Linux, 32 bytes of the alphabet on Windows), occasional unreachables, Neighbor Discovery on IPv6.
Security notes
- Reconnaissance: ping sweeps (
nmap -sn), and UDP port scans rely on port-unreachable replies. Timestamp (13/14) and address mask (17/18) replies leak information; block them. - ICMP tunnels and exfiltration: data hidden in echo payloads (
icmpsh,ptunnel,hans). Look for large or high-entropy payloads, non-standard sizes, many echoes to one external host. - Smurf / amplification: echo requests to a broadcast address with a spoofed source. Routers no longer forward directed broadcasts by default.
- Redirect attacks: forged type 5 (ICMPv6 137) messages change a host’s route; ignore redirects on hosts.
- Ping of death / floods: oversized fragmented echoes crashed old stacks; floods are still a cheap DoS. Rate-limit rather than block.
- Do not block ICMP blindly: PMTUD and, in IPv6, Neighbor Discovery depend on it. RFC 4890 lists what to allow.
Versions and related
- ICMPv6 (RFC 4443) takes over ARP, router discovery and multicast membership (MLD) for IPv6.
- IPv4: TTL, DF and the Protocol field drive most ICMP messages.
- IGMP (protocol 2) handles multicast membership for IPv4.
References
- RFC 792: Internet Control Message Protocol
- RFC 4443: ICMPv6
- RFC 1191: Path MTU Discovery
- RFC 4890: Recommendations for filtering ICMPv6 in firewalls
- IANA ICMP parameters