networking 6 min read

Understanding ICMP & the Ping Tool: A Deep Dive for Developers

Understanding ICMP & the Ping Tool: A Deep Dive for Developers

What Is ICMP?

ICMP — the Internet Control Message Protocol — is one of the core protocols of the Internet Protocol suite. Defined in RFC 792 (1981), it lives at the Network Layer (Layer 3) of the OSI model, sitting alongside IP rather than on top of it like TCP or UDP.
Unlike TCP or UDP, ICMP is not used to exchange data between applications. Its purpose is purely diagnostic and control: it lets network devices report errors, check reachability, and communicate operational information back to the source of a packet.

How ICMP Works

Every ICMP message is encapsulated inside an IP packet but has no port numbers — it belongs to the network layer itself. An ICMP message has a compact structure:
FieldSizeDescription
Type1 byteCategory of the message (e.g. Echo Request = 8)
Code1 byteSub-type / detail within the Type
Checksum2 bytesError detection over the header + data
DatavariesDepends on Type/Code

Common ICMP Types

TypeNameDirectionCommon Use
0Echo Reply← responseReply to a ping
3Destination Unreachable← errorPort/host/net not reachable
5Redirect← routerBetter route available
8Echo Request→ outboundThe "ping" packet itself
11Time Exceeded← errorTTL hit zero (used by traceroute)
IPv6 note: ICMPv6 (RFC 4443) is the equivalent for IPv6 and also handles neighbor discovery (ARP replacement) and MLD (multicast).

The TTL Field and Why It Matters

Every IP packet carries a Time To Live (TTL) field — an integer decremented by 1 at each router hop. When it reaches 0, the packet is discarded and the router sends back an ICMP Type 11 — Time Exceeded message.
This mechanism prevents packets from looping forever and is what traceroute exploits: it sends packets with TTL = 1, then TTL = 2, etc., collecting the "Time Exceeded" replies to map each hop along the route.

The ping Tool

ping is the most widely known use of ICMP. It sends ICMP Echo Request (Type 8) packets to a target and waits for ICMP Echo Reply (Type 0) packets in return.

Basic Usage

Bash
ping google.com
CODE
PING google.com (142.250.74.46) 56(84) bytes of data.
64 bytes from 142.250.74.46: icmp_seq=1 ttl=117 time=12.3 ms
64 bytes from 142.250.74.46: icmp_seq=2 ttl=117 time=11.9 ms
64 bytes from 142.250.74.46: icmp_seq=3 ttl=117 time=12.1 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 11.9/12.1/12.3/0.163 ms

Reading the Output

FieldMeaning
bytesSize of the ICMP payload sent
icmp_seqSequence number — helps detect out-of-order or lost packets
ttlRemaining TTL when the reply arrived
timeRound-Trip Time (RTT) in milliseconds
packet loss% of sent packets that got no reply
mdevMean deviation — a measure of jitter

Useful Flags

Bash
# Send only 4 packets (default on Windows, optional on Linux/macOS)
ping -c 4 google.com
 
# Set a custom packet size (bytes)
ping -s 1400 google.com
 
# Set TTL manually (useful for hop-counting experiments)
ping -t 5 google.com        # macOS/BSD
ping --ttl 5 google.com     # Linux
 
# Flood ping — sends as fast as possible (requires root)
sudo ping -f 192.168.1.1
 
# Specify interval between packets (seconds)
ping -i 0.2 google.com
 
# Quiet output — only print summary
ping -q -c 10 google.com

What Ping Can (and Cannot) Tell You

✅ What ping tells you

  • Host reachability — is the IP responding at all?
  • Round-trip latency — how long is the path?
  • Packet loss — is the network dropping packets?
  • Jitter — how consistent is the latency? (look at mdev)
  • Basic DNS resolution — if you ping a hostname, it resolves it first

❌ What ping does NOT tell you

  • Whether a specific service (HTTP, SSH, etc.) is running — a host can reply to ping but have port 80 closed
  • Whether firewalls are blocking traffic — many firewalls silently drop ICMP without sending back a "Destination Unreachable"
  • Application-level performance — latency to ping ≠ latency for your API

ICMP and Firewalls

ICMP is sometimes blocked by firewalls or cloud security groups. A common misconception is that a host "is down" if ping fails — in reality it may simply have ICMP filtered.
Bash
# Host unreachable (network-level)
ping 10.0.0.99
# Request timeout for icmp_seq 1
# ...
 
# vs. host up but ICMP blocked — same symptom, different cause
💡 Tip: If ping fails but curl or ssh works, the host is up — ICMP is just firewalled. Use tools like nmap, nc, or curl to probe specific ports.

ICMP in Everyday DevOps

ScenarioICMP Role
Health checks in load balancersPing-based checks to verify backend node reachability
Network monitoring (Nagios, Zabbix)ICMP Echo as the simplest liveness probe
Latency baselinesContinuous ping to track RTT trends over time
traceroute / tracepathUses TTL expiry + ICMP Time Exceeded to map routes
MTU discovery (PMTUD)ICMP "Fragmentation Needed" (Type 3, Code 4) negotiates MTU

Quick Recap

CODE
You type:  ping google.com
           │
           ├─ DNS resolves google.com → 142.250.74.46
           │
           └─ Your OS sends:  IP packet
                                └─ ICMP Type 8 (Echo Request)
                                      └─ payload + sequence number

Google responds:  IP packet
                   └─ ICMP Type 0 (Echo Reply)
                         └─ same payload mirrored back

Your terminal shows: RTT, TTL, sequence number
ICMP is small, stateless, and incredibly useful. Mastering what it reports — and what it doesn't — is a foundational skill for anyone working with networks, infrastructure, or distributed systems.

Thanks for reading! If you found this useful, check out the follow-up post on traceroute and path analysis using ICMP and UDP.
20 views
2 comments

Discussion

Comments are moderated.

Nice

Nice