Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 40 of 46

Lesson: ICMPSwitch
โ† Linux Foundations

Network operations

ICMP

How the Internet Control Message Protocol reports errors and answers reachability tests.

When a packet cannot be delivered, IP on its own says nothing. The Internet Control Message Protocol (ICMP) is the part of the network layer that sends news back: "I could not reach that", "this packet ran out of hops", or simply "yes, I am here". It is defined in RFC 792 for IPv4. IPv6 has its own version, ICMPv6.

Where ICMP fits

An ICMP message travels inside an IP packet, using IP protocol number 1. It is not TCP or UDP, so it has no port numbers. Routers and hosts generate ICMP messages, and your own tools such as ping can send them too.

ICMP reports problems but does not fix them. It does not resend lost data, and its messages can be lost or filtered like any other packet.

Type and code

Every message starts with a type (the kind of message) and a code (the detail). These are the IPv4 values you will meet most:

| Type | Meaning | |------|---------| | 0 | Echo reply | | 3 | Destination unreachable | | 8 | Echo request | | 11 | Time exceeded |

Type 3 uses its code to say what was unreachable. Code 0 is network unreachable, code 1 is host unreachable, code 3 is port unreachable, and code 4 means the packet needed fragmentation but had the "don't fragment" flag set.

ICMPv6 uses different numbers. For example, its echo request is type 128 and its echo reply is type 129.

Time exceeded and TTL

Each IPv4 packet carries a Time To Live (TTL) value. Every router that forwards it lowers the value by at least one. When it reaches zero, the router drops the packet and normally sends a type 11 message to the sender. This stops packets from circling forever in a routing loop.

Watching ICMP

You can capture ICMP traffic with tcpdump. It needs root privileges. In one terminal:

bash
sudo tcpdump -n -i any icmp

In another, ping a host. You will see lines similar to these (newer versions also print the interface name and direction):

12:00:01.100000 IP 192.0.2.10 > 192.0.2.1: ICMP echo request, id 7, seq 1, length 64
12:00:01.101000 IP 192.0.2.1 > 192.0.2.10: ICMP echo reply, id 7, seq 1, length 64

Firewalls often block some ICMP types. A host that ignores echo requests may still serve web pages perfectly well, so silence is a clue and not proof that a machine is down. Blocking all ICMP is risky: path MTU discovery relies on the "fragmentation needed" message.

Try it

Run the capture above, then in a second terminal run ping -c 2 127.0.0.1. Match each captured line to type 8 or type 0. Add -v to tcpdump and look at the extra IP details, including the TTL. You can brush up on addresses and layers in the networking basics guide.

Check your understanding

ICMP

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.