Kahibaro
Discord Login Register

11.3 ICMP

Role of ICMP in Networks

ICMP, the Internet Control Message Protocol, is a support protocol used by IP to report problems and share control information. It does not carry user data like web pages or emails. Instead, it helps devices say things like "this route is broken," "your packet was too big," or "this host is not reachable."

ICMP is carried inside IP packets and is closely tied to the Network Layer behavior, but it is not a routing protocol and it does not establish sessions. It is best thought of as a feedback and diagnostic mechanism for IP networks.

Although ICMP has its own message types and codes, it always travels along with regular IP traffic and reacts to what happens to that traffic in transit.

ICMP is used for control and error reporting, not for transporting application data.

ICMP Message Structure

An ICMP message sits inside an IP packet. At a high level, the IP header comes first, then the ICMP header, and then additional ICMP data. The exact fields depend on the ICMP type, but there is a common pattern.

A simplified ICMP header looks like this:

FieldSize (bits)Purpose
Type8Identifies the kind of ICMP message
Code8Subtype, gives more detail about the message
Checksum16Detects errors in the ICMP header and data
Rest of hdr32Varies by type and code, may hold IDs, sequence

After this header, there is additional data. For error messages, this usually includes part of the original IP packet that caused the error. For query or echo messages, it can include identifiers, sequence numbers, and optional payloads.

The Type and Code fields are the most important for understanding what is happening. The checksum protects the ICMP content from accidental corruption.

ICMP Type identifies the main kind of message, and Code refines the meaning within that type.

ICMP Error Messages

ICMP error messages report problems that occur while delivering IP packets. Routers or hosts generate these messages when something goes wrong and send them back to the source IP address of the original packet.

Common ICMP error types include:

ICMP Type (IPv4)NameWhen It Is Sent
3Destination UnreachableDestination cannot be reached for some reason
4Source Quench (legacy)Older congestion control, now obsolete
5RedirectBetter route exists through a different router
11Time ExceededPacket's lifetime (TTL) expired while traveling
12Parameter ProblemProblem with an IP header field, usually malformed packets

The Code value for each type adds detail. For example, within Destination Unreachable (Type 3), different codes specify why the destination was unreachable.

A simplified view of some Destination Unreachable codes is:

CodeMeaning
0Network unreachable
1Host unreachable
3Port unreachable
4Fragmentation needed, but DF set

A "port unreachable" response can occur, for example, when a UDP packet is sent to a closed port on a host. The host replies with an ICMP error to say that the application endpoint is not listening.

The "fragmentation needed" code appears when a router would have to fragment a packet, but the packet was marked "do not fragment." This is important for discovering the maximum usable packet size along a path.

ICMP error messages are always sent to the original packet's source IP, and they must include part of the original packet so the sender can identify which transmission failed.

ICMP Query and Echo Messages

Not all ICMP messages are errors. Some are request and reply messages used for queries, testing, and informational purposes.

Common ICMP query types include:

ICMP Type (IPv4)NameDescription
0Echo ReplyResponse to an Echo Request
8Echo RequestUsed to test reachability, used by ping
13TimestampRequests time information (legacy)
14Timestamp ReplyReply to Timestamp

Echo Request and Echo Reply are the most visible to everyday users, because they form the basis of the ping tool. When a device receives an Echo Request addressed to it, and if configured to respond, it sends back an Echo Reply with the same identifiers and payload.

Query messages typically contain extra fields in the "rest of header" section, such as an Identifier and Sequence Number. These let the sender match replies to requests and measure things like delay between sending and receiving.

ICMP in IPv4 vs IPv6

ICMP exists for both IPv4 and IPv6, but there are differences in naming and functions.

In IPv4, the protocol is simply called ICMP. In IPv6, it is called ICMPv6. While the basic idea of control and error messaging is the same, ICMPv6 has additional responsibilities, especially around address configuration and neighbor discovery. Those details are handled in IPv6 specific chapters, so here the focus is on conceptual differences only.

A brief comparison is:

AspectICMP (IPv4)ICMPv6
Primary roleError reporting and diagnosticsError reporting, diagnostics, plus control
Address functionsLimited, uses ARP for MAC resolutionBuilt in Neighbor Discovery
Multicast and optionsLess centralStrong integration with IPv6 features

In both cases, the Type and Code fields are still used, but the actual values and meanings differ between ICMP for IPv4 and ICMPv6. Tools like ping and traceroute have versions that work over both families of protocols, using the appropriate ICMP types underneath.

ICMP and Time To Live

ICMP is closely tied to the Time To Live (TTL) field in the IPv4 header, and to the Hop Limit field in IPv6. Each router that forwards a packet decreases this value by one. If it reaches zero before the packet reaches its destination, the router discards the packet and sends an ICMP Time Exceeded message back to the source.

This behavior prevents routing loops from consuming unlimited bandwidth. When a loop exists, the TTL keeps packets from traveling forever. Instead, they eventually expire and trigger ICMP messages, which can also help network administrators detect that something is wrong.

The role of ICMP in TTL processing is only to report the expiration. The actual decrement and decision to drop the packet are considered normal IP forwarding behavior.

ICMP and Path MTU Issues

ICMP is also involved in path maximum transmission unit discovery. Packets traveling between two hosts might cross links with different maximum sizes. If a packet is larger than a router on the path can forward without fragmentation, and if the packet is marked as not fragmentable, the router drops the packet and sends back an ICMP Destination Unreachable with the appropriate code that indicates "fragmentation needed."

The ICMP message includes the MTU of the link where the problem occurred. The source can then reduce its packet size and try again. Over time, the sender discovers the largest packet size that can travel unfragmented along the path, which is the path MTU.

When a router cannot forward a too large, non fragmentable packet, it sends an ICMP "fragmentation needed" error so the sender can adjust its packet size.

ICMP and Troubleshooting

Even though specific tools are covered in their own chapters, it is useful to understand that many troubleshooting methods rely on ICMP messages.

When a device is unreachable, or when a route is broken, ICMP errors often provide the only direct feedback from the network. Messages like Destination Unreachable and Time Exceeded tell you whether a packet failed because of routing, packet size, or device availability.

ICMP also plays a role in understanding delay and packet loss. By observing responses or the absence of responses to ICMP queries, you can infer network conditions along a path. This diagnostic value is one reason ICMP, though simple, is extremely important in everyday network operations.

ICMP and Security Considerations

Because ICMP can reveal information about a network and its hosts, administrators often restrict it. Attackers may use ICMP to map networks, test what is reachable, or overload systems. At the same time, blocking all ICMP can break valid functions such as path MTU discovery and make troubleshooting more difficult.

Typical security approaches selectively allow useful ICMP types and codes while blocking others or limiting the rate of ICMP responses. For example, Echo Requests may be filtered, while essential error messages are allowed.

Completely blocking ICMP can break legitimate network functions, so ICMP filtering is usually selective rather than total.

ICMP in Everyday Operation

In daily network operation, ICMP works mostly in the background. Hosts and routers automatically send and receive ICMP messages as part of normal IP behavior. Users usually see its effects only through tools or error messages, such as when a destination is unreachable.

From a design perspective, ICMP is lightweight and stateless. It does not maintain connections, and each message stands alone. This design makes it well suited for quick notifications about problems or conditions without adding complex overhead to the network.

Views: 43

Comments

Please login to add a comment.

Don't have an account? Register now!