Unit 4: The Network Layer — Data Plane

Tutorial 8: Internet Control Message Protocol (ICMP)

Course: COMP347 Computer Networks (Revision 10)  |  Textbook: Kurose & Ross, Computer Networking: A Top‑Down Approach (9th ed.)

Table of Contents

1. Learning Objectives

Upon completion of this tutorial, students should be able to:

2. Overview

The Internet Control Message Protocol (ICMP) is an essential part of the Internet Protocol suite, operating at the network layer. Its primary purpose is to provide error reporting and diagnostic functions for IP. Unlike transport protocols like TCP or UDP, ICMP is not used to carry user data; instead, it carries control messages between hosts and routers. ICMP messages are encapsulated in IP datagrams (using protocol number 1).

ICMP is used for a variety of tasks: reporting errors (e.g., destination unreachable, time exceeded), performing diagnostics (ping, traceroute), and helping with network management (redirects, router discovery). This tutorial covers the ICMP architecture, message formats, common types and codes, and the operation of ping and traceroute. We also discuss ICMP security issues and best practices, as well as ICMPv6.

3. Detailed Technical and Theoretical Content

3.1 ICMP Architecture and Role

ICMP is defined in RFC 792. It is a control protocol that provides feedback about problems in the network environment. ICMP messages are generated by routers or hosts to report errors or to assist in troubleshooting. They are not transported like user data; they are encapsulated directly in IP datagrams.

ICMP operates as a companion to IP, but it is not a higher‑layer protocol; it is considered part of the network layer. ICMP messages are usually generated in response to IP datagrams that have encountered problems, but they can also be sent as standalone queries (e.g., Echo Request).

3.2 ICMP Message Formats

All ICMP messages begin with a common header:

The checksum covers the entire ICMP message (header + data). It uses the same one's complement algorithm as IP.

3.3 Common ICMP Types and Codes

TypeCodeDescription
00Echo Reply (ping reply)
30Destination Unreachable: Net Unreachable
31Destination Unreachable: Host Unreachable
32Destination Unreachable: Protocol Unreachable
33Destination Unreachable: Port Unreachable
34Destination Unreachable: Fragmentation Needed but DF Set (PMTUD)
36Destination Unreachable: Network Unknown
37Destination Unreachable: Host Unknown
313Destination Unreachable: Administratively Prohibited
40Source Quench (deprecated)
50Redirect: Redirect for Network
51Redirect: Redirect for Host
52Redirect: Redirect for Type of Service and Network
53Redirect: Redirect for Type of Service and Host
80Echo Request (ping)
90Router Advertisement
100Router Solicitation
110Time Exceeded: TTL expired in transit
111Time Exceeded: Fragment reassembly timeout
120Parameter Problem: Pointer indicates error
121Parameter Problem: Missing required option
122Parameter Problem: Bad length

3.4 Error Reporting: Destination Unreachable, Time Exceeded, etc.

ICMP error messages are sent when a router or host cannot process a datagram.

In error messages, the payload includes the IP header and the first 8 bytes (or more) of the original datagram that caused the error, so the sender can identify the offending packet.

3.5 Diagnostic Functions: Echo Request/Reply (Ping)

Ping uses ICMP Echo Request (Type 8) and Echo Reply (Type 0). A host sends an Echo Request to a destination; if the destination is reachable, it responds with an Echo Reply. The ping utility measures round‑trip time and packet loss, providing a basic connectivity test.

Ping is widely used for troubleshooting network connectivity, but it can be blocked by firewalls for security reasons.

3.6 Traceroute Using ICMP

Traceroute is a diagnostic tool that maps the path from a source to a destination. It exploits ICMP Time Exceeded messages. The source sends a series of packets with increasing TTL values (starting at 1). Each router along the path decrements the TTL; when TTL reaches 0, the router discards the packet and sends an ICMP Time Exceeded (type 11) back to the source. The source records the source IP of each ICMP message, revealing the router's address. The process continues until the destination is reached (usually by using a UDP packet to a high port, triggering an ICMP Port Unreachable from the destination, or using ICMP Echo Request with TTL large enough).

There are variations: some implementations use UDP packets (traceroute on Linux typically uses UDP), while others use ICMP Echo Requests (Windows tracert). Both rely on ICMP Time Exceeded and Port Unreachable.

3.7 Other ICMP Messages: Redirect, Router Discovery

3.8 ICMP Security: Filtering, Attacks, and Best Practices

ICMP can be abused in various attacks:

Best practices: Many organizations block incoming ICMP Echo Requests at the perimeter to hide hosts and prevent attacks. However, this can break Path MTU Discovery and other diagnostics. It is recommended to allow ICMP messages that are essential (e.g., Destination Unreachable, Time Exceeded for PMTUD) and rate‑limit others.

3.9 Advanced Topics: ICMPv6, Path MTU Discovery, and Extension Headers

ICMPv6 (RFC 4443): ICMP for IPv6. It has a similar structure but with additional types: Neighbor Discovery (NDP) messages (Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement) are part of ICMPv6. ICMPv6 also includes Packet Too Big messages for Path MTU Discovery.

Path MTU Discovery (PMTUD): ICMP plays a crucial role in PMTUD. When a router needs to fragment a datagram but the DF flag is set, it sends an ICMP Destination Unreachable (type 3, code 4) message back to the source, indicating the MTU of the next hop. The source can then adjust its packet size.

4. Quiz Section

Multiple‑Choice Questions

Q1. What is the protocol number for ICMP in the IP header?

Show Answer

A) 1

Q2. Which ICMP type is used for Echo Reply?

Show Answer

A) 0

Q3. An ICMP Destination Unreachable message is sent when:

Show Answer

B) A datagram cannot be delivered

Q4. Which ICMP type is used for Time Exceeded?

Show Answer

B) 11

Q5. The ping utility uses which ICMP message types?

Show Answer

A) Echo Request (8) and Echo Reply (0)

Q6. Traceroute primarily uses which ICMP message type to discover routers?

Show Answer

C) Time Exceeded (Type 11)

Q7. Which ICMP code indicates "Fragmentation Needed but DF Set" (PMTUD)?

Show Answer

D) Code 4 (Destination Unreachable, type 3, code 4)

Q8. ICMP messages are encapsulated in:

Show Answer

C) IP datagrams

Q9. The ICMP checksum covers:

Show Answer

B) The entire ICMP message

Q10. Which ICMP message type is used to inform a host of a better route?

Show Answer

C) Redirect (Type 5)

Q11. Which of the following is NOT a valid ICMP Destination Unreachable code?

Show Answer

D) TTL Expired is Time Exceeded (Type 11).

Q12. In an ICMP error message, the payload typically includes:

Show Answer

B) The IP header plus at least the first 8 bytes of the original payload

Q13. ICMPv6 is defined in:

Show Answer

B) RFC 4443

Q14. Which ICMP message is deprecated and should not be used?

Show Answer

B) Source Quench (Type 4)

Q15. The Smurf attack exploits which ICMP feature?

Show Answer

A) Echo Request to a broadcast address with spoofed source.

Q16. In ICMP, the 'Type' field is how many bits?

Show Answer

B) 8

Q17. Which ICMP type is used for Router Advertisement?

Show Answer

A) 9

Q18. The purpose of ICMP Parameter Problem (Type 12) is:

Show Answer

B) To report an error in the IP header

Q19. Which of the following is a common defense against ICMP attacks?

Show Answer

D) Both A and B (but blocking all can break PMTUD; selective filtering is better).

Q20. In IPv6, which ICMPv6 message is used for Path MTU Discovery?

Show Answer

A) Packet Too Big (ICMPv6 type 2).

Q21. Traceroute on Windows (tracert) typically uses:

Show Answer

B) ICMP Echo Requests with increasing TTL.

Q22. ICMP Redirect messages are typically sent by:

Show Answer

C) A router

Q23. Which ICMP type is used for Echo Request?

Show Answer

B) 8

Q24. The ICMP "Port Unreachable" message is used by:

Show Answer

B) UDP (it is sent by a host when a UDP datagram arrives for a port with no listener; also used by traceroute when using UDP).

Q25. Which of the following is NOT a function of ICMP?

Show Answer

C) Routing of user data (that is IP's job).

Q26. In ICMP, the checksum is calculated over the ICMP message using:

Show Answer

B) One's complement sum (same as IP checksum).

Q27. ICMP Time Exceeded (code 1) indicates:

Show Answer

B) Fragment reassembly timeout (code 0 is TTL expired).

Q28. The 'Ping of Death' attack involved:

Show Answer

B) Sending oversized ICMP packets that exceeded the maximum size.

Q29. Which ICMP message is used by routers to solicit configuration from a DHCP server?

Show Answer

D) None of the above – DHCP uses UDP, not ICMP.

Q30. ICMPv6 Neighbor Discovery (NDP) replaces which IPv4 protocol?

Show Answer

A) ARP (Address Resolution Protocol).

Short‑Answer Questions

Q31. Explain the difference between ICMP Type 3, Code 3 and Type 3, Code 4.

Show Answer

Type 3 is Destination Unreachable. Code 3 is Port Unreachable, indicating that the destination host does not have the specified port open. Code 4 is Fragmentation Needed but DF Set, used in Path MTU Discovery to tell the source that the packet is too large and cannot be fragmented.

Q32. Why is ICMP considered part of the network layer, not the transport layer?

Show Answer

ICMP is encapsulated directly in IP datagrams (protocol number 1) and does not use port numbers. It provides control and error messages for the IP layer itself, which is characteristic of the network layer. It is not used to transport user data.

Q33. How does a host know that an ICMP Echo Reply corresponds to a particular Echo Request?

Show Answer

Each Echo Request contains an Identifier and a Sequence Number in the payload. The Echo Reply echoes these back, allowing the sender to match replies to requests.

Q34. What is the purpose of ICMP Redirect messages and why might they be considered a security risk?

Show Answer

ICMP Redirect informs a host of a better route to a destination. A malicious user could send forged Redirect messages to alter a host's routing table, directing traffic to an attacker's machine, enabling man‑in‑the‑middle attacks.

Q35. Describe the role of ICMP in Path MTU Discovery and explain what happens if ICMP messages are blocked.

Show Answer

PMTUD uses ICMP Fragmentation Needed (Type 3, Code 4) messages to inform the source of a smaller MTU. If these ICMP messages are blocked, the source never learns the correct MTU and may continue sending large packets that are dropped, causing a "black hole" condition where connections hang.

Scenario‑Based Questions

Q36. A user reports that they cannot ping a remote server, but they can traceroute to it. What could be the reason?

Show Answer

The remote server or an intermediate firewall may block ICMP Echo Requests (type 8) but allow other ICMP types (like Time Exceeded) needed for traceroute. Also, the server may be configured to ignore pings but still send ICMP errors.

Q37. A router receives a datagram with TTL=1 and forwards it? What happens? What ICMP message is generated?

Show Answer

The router decrements TTL to 0, discards the datagram, and sends an ICMP Time Exceeded (Type 11, Code 0) back to the source.

Q38. A host sends a UDP datagram to a destination port that is not open. What ICMP message does the destination host send back?

Show Answer

The destination host will send an ICMP Destination Unreachable (Type 3) with Code 3 (Port Unreachable).

Q39. In a traceroute, the source receives ICMP Time Exceeded from router R1, then from R2, but then no response. What might be the issue?

Show Answer

Either the destination host is unreachable (no route), the packets are being filtered, or the destination host does not send ICMP Port Unreachable (if using UDP traceroute) or Echo Reply (if using ICMP traceroute). Firewalls may block the final probe.

Q40. Explain how an attacker could use ICMP Redirect to perform a man‑in‑the‑middle attack.

Show Answer

The attacker sends a forged ICMP Redirect message to a host, claiming that a better route to a specific destination is via the attacker's machine. The host updates its routing table and sends subsequent traffic to the attacker, who can then intercept, modify, or forward the traffic.

Q41. Why is it recommended to filter incoming ICMP Echo Requests at the perimeter? What is the trade‑off?

Show Answer

Filtering prevents external hosts from discovering internal hosts and reduces attack surface (ping floods). The trade‑off is that legitimate diagnostics from external sources (e.g., monitoring tools) may not work, and internal hosts cannot ping external hosts if the filter is applied to outgoing as well (usually it's incoming only).

Q42. A network administrator notices that ICMP Time Exceeded messages are being dropped by a firewall. How would this affect traceroute?

Show Answer

Traceroute relies on receiving ICMP Time Exceeded messages from intermediate routers to build the path. If these are dropped, traceroute will show asterisks (*) for those hops and may not be able to complete, making it difficult to diagnose routing paths.

Q43. What is the difference between ICMP Echo Request and Echo Reply in terms of the 'Type' field?

Show Answer

Echo Request has Type = 8, Echo Reply has Type = 0. Both have Code = 0.

Q44. In IPv6, which ICMPv6 messages are used for Neighbor Discovery?

Show Answer

Neighbor Solicitation (NS, Type 135), Neighbor Advertisement (NA, Type 136), Router Solicitation (RS, Type 133), Router Advertisement (RA, Type 134).

Q45. Why is the ICMP checksum required, given that IP has its own checksum?

Show Answer

The IP checksum only covers the IP header, not the payload. ICMP messages are the payload of IP datagrams, so ICMP needs its own checksum to ensure the integrity of the ICMP message itself.

Q46. How does a host determine the path MTU using ICMP? Describe the steps.

Show Answer

The host sends a large packet with the DF flag set. If a router on the path has a smaller MTU, it drops the packet and sends an ICMP Destination Unreachable (Type 3, Code 4) back, including the MTU of the next hop. The host then reduces the packet size and retransmits, repeating until no such messages are received, thus discovering the path MTU.

Q47. What is the 'Identifier' field used for in ICMP Echo messages?

Show Answer

The Identifier is used to match Echo Requests with Echo Replies, allowing multiple concurrent ping sessions. It is often set to the process ID or a random number.

Q48. Can ICMP messages themselves be fragmented? Why or why not?

Show Answer

Yes, ICMP messages are encapsulated in IP datagrams, which can be fragmented if they exceed the MTU. However, ICMP error messages are usually small (about 64 bytes) and rarely fragment.

Q49. What is the role of the 'Next Hop MTU' field in ICMP Fragmentation Needed messages?

Show Answer

It provides the MTU of the link that caused the fragmentation failure, allowing the source to adjust its packet size accordingly.

Q50. A host sends a ping to a destination but receives "Destination Unreachable" with code 1. What does this indicate?

Show Answer

Code 1 for Destination Unreachable is Host Unreachable, meaning the router could not forward the datagram to the destination host (likely no route to the host).

5. Exercise Section

Exercise 1

What is the ICMP type and code for a message that indicates "Network Unreachable"?

Show Solution

Type = 3 (Destination Unreachable), Code = 0 (Network Unreachable).

Exercise 2

Explain the difference between ICMP Type 11, Code 0 and Type 11, Code 1.

Show Solution

Type 11 is Time Exceeded. Code 0 indicates TTL expired in transit (sent by a router when TTL becomes 0). Code 1 indicates fragment reassembly timeout (sent by a host when not all fragments arrive within the timer).

Exercise 3

A traceroute using ICMP Echo Requests receives a "Time Exceeded" from router R1, then from R2, but then a "Destination Unreachable" (Port Unreachable) from the destination. What does this indicate about the path?

Show Solution

It indicates that the path to the destination is complete: routers R1 and R2 are intermediate, and the final destination responded with Port Unreachable (since the probe used a high port, indicating the destination is reachable).

Exercise 4

Why is ICMP redirect considered a security risk? Propose a mitigation.

Show Solution

ICMP redirect can be spoofed to alter routing tables, leading to MITM attacks. Mitigation: ignore ICMP redirect messages on hosts, or configure routers to not send them.

Exercise 5

How does Path MTU Discovery use ICMP to determine the optimal packet size?

Show Solution

PMTUD sends packets with the DF flag set. When a router with a smaller MTU receives such a packet, it drops it and sends an ICMP Destination Unreachable (Type 3, Code 4) with the MTU of the next hop. The source reduces its packet size and retries until no such ICMP messages are received, establishing the path MTU.

Exercise 6

A network administrator wants to allow ping but block ICMP Redirect messages. What firewall rules should they implement?

Show Solution

Allow ICMP Type 0 (Echo Reply) and Type 8 (Echo Request) for ping. Block ICMP Type 5 (Redirect). Additionally, allow necessary error types (Type 3, Type 11) for PMTUD and diagnostics.

Exercise 7

What is the ICMP message sent when a router receives a datagram with an invalid IP header option?

Show Solution

ICMP Parameter Problem (Type 12). Code 0 indicates pointer indicates error, or Code 1 for missing required option, etc.

Exercise 8

Explain how ICMP can be used for network reconnaissance (e.g., ping sweeps). How can this be mitigated?

Show Solution

An attacker can send ICMP Echo Requests to a range of IP addresses to find live hosts (ping sweep). Mitigation: block incoming ICMP Echo Requests at the firewall, or rate‑limit them.

Exercise 9

A host sends a ping to a destination but receives no reply and no error message. What could be the reasons?

Show Solution

Possible reasons: ICMP traffic is blocked by a firewall, the destination is down, the destination does not respond to pings, or the packets are being dropped due to congestion or routing issues.

Exercise 10

Describe the difference between ICMP Router Solicitation and Router Advertisement.

Show Solution

Router Solicitation (Type 10) is sent by a host to request router information; Router Advertisement (Type 9) is sent by routers periodically or in response to solicitations to inform hosts of router addresses and parameters.

Exercise 11

What is the ICMP message used for "Fragmentation Needed but DF set" and what is its code?

Show Solution

Type 3 (Destination Unreachable), Code 4.

Exercise 12

Explain why ICMP error messages are not sent in response to other ICMP error messages (to avoid storms).

Show Solution

To prevent infinite loops and flooding, ICMP error messages are not generated for errors that occur while processing other ICMP error messages, for fragmented packets (except the first fragment), or for broadcast/multicast packets.

Exercise 13

What is the default TTL used by ping on most operating systems? How does this affect packet traversal?

Show Solution

Typically 64 (Linux) or 128 (Windows). This limits the number of hops the packet can traverse; if the destination is farther than the TTL, the packet will be dropped with Time Exceeded.

Exercise 14

How does ICMPv6 differ from ICMPv4 in terms of error handling and neighbor discovery?

Show Solution

ICMPv6 includes Neighbor Discovery (NDP) which replaces ARP and other IPv4 functions. ICMPv6 has additional types for NDP (Router Solicitation, Router Advertisement, Neighbor Solicitation, Neighbor Advertisement). Error messages are similar but adapted for IPv6.

Exercise 15

An ICMP Echo Request has Identifier = 0x1234 and Sequence = 5. What will the Echo Reply contain for these fields?

Show Solution

The Echo Reply will contain the same Identifier (0x1234) and Sequence (5) to allow matching.

6. Homework Section

Homework 1

Research the history of ICMP and its evolution. Write a 500‑word essay covering its creation, key RFCs, and how it has adapted to new requirements (e.g., IPv6).

Show Sample Answer

ICMP was defined in RFC 792 (1981). It has been extended with new types and codes. ICMPv6 (RFC 4443) introduced Neighbor Discovery. ICMP remains essential for network diagnostics and control.

Homework 2

Compare and contrast ICMP Echo Request/Reply (ping) with TCP SYN‑based connectivity tests (e.g., hping). Discuss the advantages and disadvantages of each.

Show Sample Answer

Ping is simple, lightweight, and widely available, but can be blocked. TCP SYN tests can bypass some filters but require open ports and may be seen as scanning. TCP tests also measure application‑layer connectivity.

Homework 3

Explain the role of ICMP in the "ping of death" attack and how modern systems protect against it.

Show Sample Answer

The ping of death sent oversized ICMP packets that caused buffer overflows. Modern systems check packet size before processing and reject oversized packets.

Homework 4

Describe how ICMP is used for router discovery and why it has been largely replaced by DHCP.

Show Sample Answer

Router Discovery (ICMP Router Solicitation/Advertisement) allows hosts to find routers. DHCP provides more comprehensive configuration (IP, DNS, etc.) and is more widely used.

Homework 5

Investigate the concept of "ICMP tunneling" and how it can be used for covert communication.

Show Sample Answer

ICMP tunneling encapsulates other protocols within ICMP Echo packets to bypass firewalls. It can be used for data exfiltration or covert channels.

Homework 6

Explain the difference between ICMP error messages for "Network Unreachable" and "Host Unreachable". When might each occur?

Show Sample Answer

Network Unreachable (code 0) means the router has no route to the network. Host Unreachable (code 1) means the router has a route to the network but cannot reach the specific host (e.g., ARP failure).

Homework 7

Describe the process of a typical traceroute implementation that uses UDP packets. Why does it need ICMP?

Show Sample Answer

Traceroute sends UDP packets with increasing TTL. Routers send ICMP Time Exceeded (type 11) when TTL expires. The destination sends ICMP Port Unreachable (type 3, code 3) when the UDP packet reaches a closed port, indicating the end of the path.

Homework 8

What are the security considerations for allowing ICMP in a corporate network? Write a policy recommendation.

Show Sample Answer

Recommend allowing essential ICMP types (Echo Request, Echo Reply, Destination Unreachable, Time Exceeded) but rate‑limit them. Block Redirect and Router Solicitation/Advertisement. Use ACLs to restrict internal ICMP.

Homework 9

Explain the concept of "ICMP redirect" and why it is often disabled on hosts and routers.

Show Sample Answer

ICMP redirect informs a host of a better route. It is often disabled to prevent potential MITM attacks and because routing is better handled by dynamic routing protocols.

Homework 10

How does ICMPv6 handle Neighbor Discovery and what are the main message types?

Show Sample Answer

ICMPv6 Neighbor Discovery includes Router Solicitation (133), Router Advertisement (134), Neighbor Solicitation (135), Neighbor Advertisement (136), and Redirect (137). It replaces ARP and handles address resolution and router discovery.

Homework 11

Discuss the impact of ICMP rate limiting on network diagnostics. How can network administrators balance security and usability?

Show Sample Answer

Rate limiting can delay diagnostic responses. Administrators can set reasonable thresholds, allow specific sources (e.g., internal monitoring), or use alternative tools like TCP‑based tests.

Homework 12

What is the purpose of the ICMP "Source Quench" message and why is it obsolete?

Show Sample Answer

Source Quench (Type 4) was intended to signal congestion to the source. It is obsolete because it is not effective and can be abused; TCP congestion control is now used.

Homework 13

Describe how ICMP is used in the "Smurf" attack and how it can be mitigated.

Show Sample Answer

Smurf sends ICMP Echo Requests to a broadcast address with spoofed source, causing all hosts to reply to the victim. Mitigation: disable directed broadcasts on routers, filter spoofed packets.

Homework 14

Explain the relationship between ICMP and Path MTU Discovery. What happens if ICMP Fragmentation Needed messages are filtered?

Show Sample Answer

PMTUD relies on ICMP Type 3, Code 4. If filtered, the source never learns the MTU, leading to packet loss and connection stalls (black hole).

Homework 15

Compare the ICMP implementation in IPv4 and IPv6, focusing on the changes and new functionalities.

Show Sample Answer

IPv6 ICMP (ICMPv6) includes Neighbor Discovery, which replaces ARP. It also has new types like Packet Too Big. Error messages are similar but adapted for 128‑bit addresses.

7. Summary

This tutorial has provided a comprehensive exploration of the Internet Control Message Protocol (ICMP). Key takeaways:

Understanding ICMP is essential for network troubleshooting, security, and understanding how the network layer supports diagnostics. In the next tutorial, we will explore IPv6 architecture and operations.