Internet Control Message Protocol (ICMP)

Comprehensive Study Guide for Undergraduate Communication Engineering

🌐 Introduction to ICMP

The Internet Control Message Protocol (ICMP) is a network layer protocol used by network devices, including routers, to send error messages and operational information indicating success or failure when communicating with another IP address. Defined in RFC 792, ICMP is an integral part of the Internet Protocol Suite.

Key Concept: ICMP is not a transport layer protocol like TCP or UDP. It is a supporting protocol for IP that provides feedback about problems in the communication environment, not designed to carry application data.

Purpose of ICMP

💻
Host A
🌐
Router
🖥️
Host B

🎮 Interactive Demo: ICMP in Action

Click the buttons below to simulate different ICMP scenarios:

Click a button above to see ICMP message flow visualization

⚙️ Key Characteristics

ICMP Features

  • Works at Network Layer (Layer 3)
  • Encapsulated in IP datagrams
  • No port numbers (unlike TCP/UDP)
  • Unreliable delivery (no ACK)
  • Used by network devices and hosts

ICMP Limitations

  • Cannot report errors on ICMP errors
  • No flow control mechanism
  • No authentication (security risk)
  • Not designed for data transfer
  • Subject to rate limiting

Encapsulation

ICMP messages are encapsulated directly within IP datagrams. The IP protocol field value for ICMP is 1 (0x01).

IP Header
Protocol = 1
ICMP Header
8 bytes
ICMP Data
Variable
Important: ICMP messages are subject to IP routing and fragmentation just like any other IP datagram. However, ICMP error messages must not be sent in response to:
  • Another ICMP error message
  • IP datagram with broadcast/multicast destination
  • IP datagram with source address 0.0.0.0 or loopback
  • Fragment other than the first fragment

📦 ICMP Message Format

All ICMP messages share a common header format consisting of an 8-byte header followed by variable-length data.

Type
8 bits
Code
8 bits
Checksum
16 bits
Rest of Header (Content varies by type)
32 bits
Data Section (Variable length)
Contains original datagram info + padding

Field Descriptions

Field Size Description
Type 8 bits Identifies the ICMP message type (e.g., 0=Echo Reply, 3=Destination Unreachable)
Code 8 bits Provides additional granularity for the Type (e.g., Type 3, Code 0 = Net Unreachable)
Checksum 16 bits Error detection for ICMP header and data (one's complement sum)
Rest of Header 32 bits Content varies: unused (0), pointer, identifier/sequence number, or gateway address
Data Variable For error messages: IP header + first 8 bytes of original data. For queries: arbitrary data
Checksum Calculation:
Checksum = ~(Sum of all 16-bit words in ICMP message)
If result is 0, checksum field is set to 0xFFFF (one's complement arithmetic)

📋 ICMP Message Types

ICMP messages are categorized into two classes: Error Messages (Types 0-127) and Query/Informational Messages (Types 128-255).

Error Messages

Type Name Description Common Codes
3 Destination Unreachable Network/host/port unreachable or fragmentation needed 0=Net, 1=Host, 3=Port, 4=Frag needed
4 Source Quench Congestion control (deprecated) 0
5 Redirect Router suggests better route 0=Net, 1=Host, 2=TOS+Net, 3=TOS+Host
11 Time Exceeded TTL decremented to 0 or fragment reassembly timeout 0=TTL, 1=Frag reassembly
12 Parameter Problem Malformed IP header or missing required option 0=Pointer, 1=Missing option, 2=Bad length

Query Messages

Type Name Description Request/Reply
0 Echo Reply Response to Echo Request (Ping reply) Reply
8 Echo Request Request for connectivity test (Ping) Request
9 Router Advertisement Router announces its presence Reply
10 Router Solicitation Host requests router advertisement Request
13 Timestamp Request Request for timestamp information Request
14 Timestamp Reply Response to timestamp request Reply

🎯 Key Points to Remember

  • Type 0 and 8 are the most commonly used (Ping utility)
  • Type 3 indicates delivery failures - check Code field for specifics
  • Type 11 is crucial for traceroute functionality
  • Type 5 is used by routers to optimize host routing tables

⚠️ Error Reporting Mechanisms

1. Destination Unreachable (Type 3)

Generated when a datagram cannot be delivered to its destination. The Code field specifies the reason:

Code Meaning When Generated
0 Network Unreachable Routing table has no route to destination network
1 Host Unreachable Destination host not responding to ARP
2 Protocol Unreachable Specified protocol not active on destination
3 Port Unreachable No process listening on destination port (UDP)
4 Fragmentation Needed DF bit set but MTU smaller than datagram
5 Source Route Failed Cannot follow specified source route
Example: ICMP Port Unreachable Scenario

Host A sends UDP packet to Host B:192.168.1.10:33456

Host B checks port 33456 - no application listening

Host B sends ICMP Type 3, Code 3 to Host A

Host A's application receives "Connection refused" error

2. Time Exceeded (Type 11)

Generated in two scenarios:

Path MTU Discovery: Uses ICMP Type 3, Code 4 (Fragmentation Needed) with the Don't Fragment (DF) bit to discover the maximum transmission unit along a path without fragmentation.

3. Redirect (Type 5)

Routers send redirect messages to hosts to inform them of better routes:

🔧 Diagnostic Tools

Ping (Packet Internet Groper)

The most common ICMP utility used to test reachability and measure round-trip time.

Type: 8
(Request)
Code: 0
Checksum
Identifier
Sequence
Optional Data (Timestamp)

Operation:

  1. Source sends ICMP Echo Request (Type 8) with unique identifier and sequence number
  2. Destination receives request and swaps source/destination addresses
  3. Destination sends ICMP Echo Reply (Type 0) with same identifier and sequence
  4. Source calculates RTT by comparing timestamps
Sample Ping Output Analysis:

$ ping -c 4 google.com
PING google.com (142.250.80.46): 56 data bytes
64 bytes from 142.250.80.46: icmp_seq=0 ttl=117 time=15.3 ms
64 bytes from 142.250.80.46: icmp_seq=1 ttl=117 time=14.8 ms
64 bytes from 142.250.80.46: icmp_seq=2 ttl=117 time=15.1 ms
64 bytes from 142.250.80.46: icmp_seq=3 ttl=117 time=14.9 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 14.8/15.0/15.3/0.2 ms

Traceroute

Uses ICMP or UDP to trace the route path:

Note: Many routers today filter ICMP messages for security reasons, which may cause traceroute to show asterisks (*) for some hops. This doesn't necessarily mean the network is down—just that ICMP is blocked.

🔒 Security Considerations

Common ICMP Attacks

Attack Type Description ICMP Type Used Mitigation
Ping Flood DoS attack using massive ICMP echo requests Type 8 Rate limiting, ICMP filtering
Smurf Attack Spoof source address, send to broadcast Type 8 Disable directed broadcast
ICMP Redirect Man-in-the-middle via fake redirects Type 5 Ignore ICMP redirects
ICMP Tunneling Hide data in ICMP payload Any Deep packet inspection
OS Fingerprinting Identify OS by ICMP behavior Various Standardize ICMP responses
Best Practice: Many firewalls block ICMP by default. However, blocking all ICMP can break Path MTU Discovery (causing "black hole" connections) and make troubleshooting difficult. Recommended approach: Allow ICMP Types 0, 3, 4, 8, 11, 12 and block others.

🚀 Applications & Real-World Usage

1. Path MTU Discovery (PMTUD)

Critical for avoiding IP fragmentation:

2. Dead Gateway Detection

Hosts use ICMP to detect router failures:

3. Network Management

SNMP and monitoring tools rely on ICMP for:

4. ICMP in IPv6 (ICMPv6)

ICMPv6 (RFC 4443) is significantly expanded:

📝 Summary

Key Takeaways

  • ICMP is a Network Layer protocol (IP Protocol 1) for error reporting and diagnostics
  • Message format: 8-byte header (Type, Code, Checksum, Rest) + variable data
  • Type 0/8: Echo Reply/Request (Ping) - most common usage
  • Type 3: Destination Unreachable - delivery failure notification
  • Type 11: Time Exceeded - TTL or reassembly timeout
  • Type 5: Redirect - route optimization (security risk)
  • Essential for network troubleshooting but often filtered for security
  • ICMPv6 expands functionality to replace ARP and IGMP in IPv6

Quick Reference Card

Type Name Key Codes Usage
0 Echo Reply 0 Ping response
3 Dest Unreachable 0-15 Delivery failures
5 Redirect 0-3 Route optimization
8 Echo Request 0 Ping request
11 Time Exceeded 0-1 Traceroute, loops
12 Param Problem 0-2 Header errors

Quick Knowledge Check

Click on questions to reveal answers:

Q1: Why doesn't ICMP use port numbers like TCP and UDP?
ICMP operates at the Network Layer (Layer 3) alongside IP, not at the Transport Layer (Layer 4). Port numbers are a Transport Layer concept used for process-to-process communication. ICMP is designed for host-to-host and router-to-host communication, identified by IP addresses and ICMP Type/Code fields.
Q2: What ICMP message types are used by the traceroute utility?
Traceroute uses two types: (1) It sends packets with incrementing TTL values, causing routers to return ICMP Time Exceeded (Type 11, Code 0) messages. (2) When it reaches the destination, it receives either ICMP Port Unreachable (Type 3, Code 3) for UDP-based traceroute or ICMP Echo Reply (Type 0) for ICMP-based traceroute.
Q3: Why should you avoid blocking all ICMP traffic at your firewall?
Blocking all ICMP breaks Path MTU Discovery (PMTUD), which relies on ICMP Type 3, Code 4 (Fragmentation Needed). Without PMTUD, connections may experience "black hole" issues where large packets are silently dropped. Additionally, blocking ICMP makes network troubleshooting difficult and can break IPv6 functionality (which relies heavily on ICMPv6).
Q4: What is the purpose of the Identifier and Sequence Number fields in ICMP Echo messages?
The Identifier field (usually the process ID) helps the operating system route replies to the correct application when multiple pings run simultaneously. The Sequence Number helps match requests with replies and detect packet loss or reordering. Together, they enable multiple concurrent ping sessions and accurate RTT measurement.
Q5: Why can't ICMP error messages be generated in response to other ICMP error messages?
This prevents "ICMP storms" or infinite loops. If Router A sends an error to Router B, and Router B generates an error about that error, they could bounce messages back and forth indefinitely. The rule states: ICMP error messages are only generated for ICMP query messages (like Echo Request), never for ICMP error messages.