ICMP & ICMPv6
Interpret ICMP echo, unreachable and time-exceeded messages.
By Invicly Tech, , in Computer Networking. About 11 minutes to read.
In short
ICMP carries control and error messages for IP. Echo request and reply power ping, time exceeded messages power traceroute, and destination unreachable messages tell senders why delivery failed. ICMPv6 is even more central, carrying neighbour discovery and router advertisements.
Explained simply
IP delivers packets on a best-effort basis: it tries, but it does not promise. When something goes wrong along the way, routers and hosts need a way to report it. That is ICMP, the Internet Control Message Protocol. It carries short messages like this network is unreachable or this packet was too big.
You use ICMP every time you run ping. Ping sends an echo request, and the target answers with an echo reply. The time between them is the round-trip time. If replies come back, you know the target is up and the path works in both directions.
Traceroute also relies on ICMP. Every packet has a TTL counter that each router lowers by one. When it hits zero, the router drops the packet and sends back an ICMP time exceeded message. By sending packets with TTL 1, 2, 3 and so on, traceroute learns each router on the path.
Some people block all ICMP for security. This causes real problems, because ICMP also tells senders when packets are too large for a link. Without that message, some connections hang mysteriously. The right approach is to allow the important ICMP types and filter the rest carefully.
Press Play on a diagram to walk through it one step at a time.
- Host to Router 1: Packet with TTL 11Packet with TTL 1
- Router 1 to Host: ICMP time exceeded (reveals Router 1)2ICMP time exceeded (reveals Router 1)
- Host to Router 1: Packet with TTL 23Packet with TTL 2
- Router 1 to Router 2: Forwarded, TTL now 14Forwarded, TTL now 1
- Router 2 to Host: ICMP time exceeded (reveals Router 2)5ICMP time exceeded (reveals Router 2)
- Echo (ping)
- IPv4: 8 request, 0 reply
- IPv6: 128 request, 129 reply
- Unreachable
- IPv4 type 3
- IPv6 type 1
- Too big
- IPv4: type 3 code 4
- IPv6: type 2 Packet Too Big
- Time exceeded
- IPv4 type 11
- IPv6 type 3
- IPv6 only
- 133 to 137: Neighbour Discovery
- 130 to 132, 143: MLD multicast
In depth
The ICMP message format
ICMP is carried inside IP with protocol number 1 (ICMPv6 uses next header 58). Every message starts with a 1-byte type, a 1-byte code that gives detail, and a 2-byte checksum, followed by 4 bytes whose meaning depends on the type. For echo messages those 4 bytes are a 16-bit identifier and a 16-bit sequence number, which ping uses to match replies to requests. ICMP has no ports; NAT devices use the identifier instead.
Error messages include the start of the packet that caused the problem: at least its IP header and first 8 bytes, which hold the TCP or UDP ports. That is how your system knows which connection the error belongs to. To avoid storms, hosts never send ICMP errors about ICMP errors, broadcasts or fragments other than the first.
- Header: type 1 byte, code 1 byte, checksum 2 bytes, then 4 bytes
- Echo: identifier and sequence number
- Errors quote the original IP header + first 8 bytes
- No ICMP errors about ICMP errors
Destination unreachable codes
Type 3 (ICMPv6 type 1) has codes that tell you exactly what failed. Code 0, network unreachable, means a router has no route. Code 1, host unreachable, usually means the last router could not get an ARP reply from the host. Code 3, port unreachable, comes from the destination host itself: the packet arrived, but nothing listens on that UDP port. Code 4, fragmentation needed and DF set, carries the next-hop MTU and drives path MTU discovery. Codes 9, 10 and 13 mean administratively prohibited: a firewall or ACL actively refused it.
On Linux, ping prints these as Destination Net Unreachable, Destination Host Unreachable and so on. If the message comes From your own IP, your host failed to ARP for a local address. If you see nothing at all, something dropped the packet silently.
- Code 0: a router has no route
- Code 1: last hop cannot ARP the host
- Code 3: host is up, port closed
- Code 13: a firewall said no
- A firewall dropped it quietly
- The host is down
- The reply path is broken
- ICMP is rate-limited
Time exceeded and how traceroute really works
Type 11 code 0 means the TTL reached zero in transit; code 1 means a host gave up reassembling fragments. Traceroute uses code 0. Linux traceroute by default sends UDP probes to high ports starting at 33434, three per TTL. Each router where TTL expires replies with time exceeded, revealing its address and the round-trip time. When a probe finally reaches the destination, the high port is closed, so the destination answers port unreachable, and traceroute knows it is done.
Windows tracert uses ICMP echo instead, and traceroute -I does the same on Linux. traceroute -T sends TCP SYNs, often to port 80 or 443, which is useful when firewalls drop UDP and ICMP. A row of asterisks means no reply within the timeout for that TTL, which does not necessarily mean the hop dropped your traffic.
- Your host to Last router: UDP to a high port, TTL 91UDP to a high port, TTL 9
- Last router to Your host: ICMP time exceeded: hop 92ICMP time exceeded: hop 9
- Your host to Destination: UDP to a high port, TTL 103UDP to a high port, TTL 10
- Destination to Your host: ICMP port unreachable: arrived, stop4ICMP port unreachable: arrived, stop
Path MTU discovery and black holes
Path MTU discovery finds the largest packet that can cross the whole path without fragmentation. In IPv4 (RFC 1191) the sender sets the DF bit; a router whose next link is too small drops the packet and returns type 3 code 4 with the next-hop MTU. In IPv6 (RFC 8201) routers always send ICMPv6 type 2, Packet Too Big. The sender lowers its packet size for that destination and resends.
If a firewall blocks those messages, you get a PMTU black hole: the TCP handshake and small requests work, but large packets vanish, so downloads stall or TLS hangs after the client hello. Fixes: allow ICMP type 3 code 4 and ICMPv6 type 2; clamp the TCP MSS on the tunnel or VPN gateway so segments fit; or enable packetization-layer probing on Linux with net.ipv4.tcp_mtu_probing=1.
- IPv4: type 3 code 4 carries the next-hop MTU
- IPv6: type 2 Packet Too Big; routers never fragment
- iptables: -j TCPMSS --clamp-mss-to-pmtu on SYN packets
- tracepath shows the discovered pmtu per hop
Learn it in 4 short steps
About 25m each. Track them with a timer in your plan.
- 1Explain echo request and reply~25m
- 2Read destination unreachable codes~25m
- 3Explain time exceeded and TTL~25m
- 4Explain path MTU discovery~25m
Key points
- Type 8 is echo request, type 0 echo reply, type 11 time exceeded.
- Type 3 code 4 (fragmentation needed) drives IPv4 path MTU discovery.
- Blocking all ICMP breaks path MTU discovery and causes stuck connections.
- ICMPv6 must be allowed for IPv6 to work at all.
Key terms
Tap a card to flip it. 0/4 known
Examples
ping -c 3 example.com
ping -M do -s 1472 -c 1 example.com # 1472 + 28 = 1500, don't fragment
sudo tcpdump -i any -nn icmpTelling no route, closed port and firewall apart
Three tests, three different answers. Step 1: ping an address in a subnet no router knows; a router answers From 10.0.0.1 Destination Net Unreachable. Step 2: send a UDP packet to a closed port on a live host; tcpdump shows ICMP udp port 9999 unreachable, so the host is up. Step 3: try a host behind a firewall that rejects; you see admin prohibited (in Linux ping output: Packet filtered). A timeout with no message at all means something dropped the packet silently, which is common on the internet.
sudo tcpdump -i any -nn 'icmp[0] == 3' &
ping -c 1 -W 2 10.99.99.99 # net or host unreachable?
nc -u -w1 10.0.0.20 9999 <<< hi # port unreachable from the host
# tcpdump: ICMP 10.0.0.20 udp port 9999 unreachableFixing a PMTU black hole on a VPN gateway
Through a new IPsec tunnel, SSH works but scp and web pages stall. Step 1: tracepath to a remote host shows pmtu 1500 at first, then the path stops responding: a sign that Packet Too Big messages are missing. Step 2: ping with DF set confirms 1400-byte packets pass but 1500-byte packets vanish silently, with no ICMP error. Step 3: on the Linux gateway, clamp the MSS of forwarded SYNs to the route MTU so TCP never sends oversized segments. Step 4: transfers now complete. Better still, also allow ICMP type 3 code 4 through the firewall so other protocols can discover the MTU too.
tracepath -n 10.30.0.10
ping -M do -s 1372 -c 2 10.30.0.10 # 1400-byte packet: OK
ping -M do -s 1472 -c 2 10.30.0.10 # 1500: silent loss
# nftables (inet filter forward chain):
sudo nft add rule inet filter forward tcp flags syn tcp option maxseg size set rt mtu
# iptables equivalent:
sudo iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtuQuick reference
- IPv4 echo: 8 request, 0 reply; IPv6 echo: 128 request, 129 reply
- Type 3 codes: 0 net, 1 host, 3 port unreachable, 4 frag needed, 13 admin prohibited
- Type 11 code 0 = TTL exceeded in transit (what traceroute uses)
- ICMPv6 type 2 = Packet Too Big; never block it
- traceroute uses UDP from port 33434; -I uses ICMP, -T uses TCP SYN
- Allow at least ICMP 3 and 11, ICMPv6 1-4 and 133-136, or things break
- tracepath host shows path MTU without root
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Ping a host 5 times and explain the icmp_seq, ttl and time values in each line, plus the summary line.
- Exercise 2medium
Run traceroute to the same host three ways (UDP, ICMP, TCP port 443) and explain why the results may differ.
- Exercise 3hard
Write nftables rules for an inet table input chain that allow essential ICMP and ICMPv6 (errors, echo, and Neighbour Discovery) and drop the rest of ICMP.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is it safe to block ping?
- Blocking echo requests from the internet hides a host from simple scans but makes troubleshooting harder. Never block ICMP error types like unreachable, time exceeded and Packet Too Big, because real traffic depends on them.
- Why does ping work but my website does not load?
- Ping only proves IP connectivity. The web server port may be closed or firewalled, the service may be down, or an MTU problem may drop the larger packets that pages need.
- What does Request timed out mean?
- No reply came back within the wait time. The host may be down, a firewall may drop ICMP, or the reply may be lost on its way back. It does not say which, so test further.
- Does ICMP use ports?
- No. ICMP sits directly on IP. Echo messages use an identifier and sequence number instead, which NAT devices track in place of ports.