Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Protocol Analysis

IP and ICMP

Understand the IPv4 header, TTL, fragmentation and DF, and ICMP echo, unreachable and time exceeded messages, with filters, a header parser and a traceroute model.

IP is the glue of the Internet: every packet carries source and destination addresses and is forwarded hop by hop. ICMP is IP's companion for error reports and diagnostics (ping and traceroute use it). Being able to read these headers lets you answer practical questions: where did the packet die, why is it so small, who sent this error?

The IPv4 header

The minimum header is 20 bytes. These are the fields Wireshark shows and that you will filter on:

Field Filter Meaning
Version / IHL ip.version, ip.hdr_len 4; header length in bytes (20 to 60)
DSCP / ECN ip.dsfield.dscp Quality-of-service marking and congestion bits
Total length ip.len Header plus data, in bytes
Identification ip.id Groups fragments of one packet; also useful for tracing
Flags ip.flags.df, ip.flags.mf Don't Fragment, More Fragments
Fragment offset ip.frag_offset Position of this fragment (8-byte units)
TTL ip.ttl Hops left; decremented by each router
Protocol ip.proto 1 ICMP, 6 TCP, 17 UDP, 47 GRE, 50 ESP, 89 OSPF
Header checksum ip.checksum Covers the header only
Source / destination ip.src, ip.dst Addresses

TTL as a fingerprint and a hint

Operating systems start the TTL at different values (commonly 64 for Linux and macOS, 128 for Windows, 255 for some network devices). When you see ttl=57 you can guess that the packet started at 64 and crossed seven routers. That is a hint, not proof. A TTL of 1 that expires triggers an ICMP error; traceroute exploits it.

Fragmentation

An IP packet larger than the link's MTU (1500 bytes for Ethernet) must be split into fragments, unless DF is set, in which case the router drops it and sends back an ICMP "Fragmentation needed" message. Fragments share the same ip.id; all but the last have the MF flag; Wireshark reassembles them and shows the whole packet on the last fragment (Reassembled IPv4 in frame N). Fragmentation is fragile and sometimes abused to slip past firewalls, so modern TCP avoids it by path MTU discovery: it sets DF and shrinks its segments when told to.

Filters: ip.flags.mf == 1 or ip.frag_offset > 0 shows fragments; ip.flags.df == 1 shows packets that may not be fragmented.

Parse a header yourself

The stand-in builds an IPv4 header, then parses it back and verifies the checksum, which is the same arithmetic Wireshark does when you enable checksum validation. Addresses use the documentation range 192.0.2.0/24.

Python Parse an IPv4 header and verify the checksum (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last line explains why routers must recompute the checksum every time they decrement the TTL.

ICMP

ICMP messages travel inside IP (protocol 1). The first two bytes are type and code. The ones you meet most:

Type Code Name Typical cause
8 0 Echo request ping
0 0 Echo reply answer to ping
3 0 Destination unreachable: network No route
3 1 Destination unreachable: host Host not found on the last hop
3 3 Destination unreachable: port UDP port closed (the host answers)
3 4 Fragmentation needed and DF set MTU problem; carries the next-hop MTU
3 13 Communication administratively prohibited A firewall rejected the packet
11 0 Time exceeded: TTL expired in transit A router decremented TTL to 0
5 0-1 Redirect A better gateway exists

Error messages contain the IP header and first 8 bytes of the packet that caused the error, so you can match them to the original. In Wireshark that nested header appears under the ICMP layer, and icmp.type, icmp.code and icmp.resp_in (the reply for a request) help. Ping replies carry the same identifier and sequence number as the request, so each pair is matched: icmp.resp_to, icmp.resptime show the round-trip time.

Some firewalls block ICMP completely. That breaks path MTU discovery and makes web pages hang on large responses but work on small ones, a classic "black hole" that you can diagnose by looking for repeated large packets with DF set and no ICMP type 3 code 4 coming back.

How traceroute works

Traceroute sends probes with TTL 1, 2, 3... Each router that decrements the TTL to 0 discards the packet and sends back ICMP time exceeded from its own address; finally the destination answers. The stand-in simulates this against an invented path; it never sends anything.

Python A traceroute model with TTL (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Useful filters

TEXT
icmp                                    ping and errors
icmp.type == 8 or icmp.type == 0        echo requests and replies
icmp.type == 3                          unreachable (check the code)
icmp.type == 11                         TTL exceeded
ip.ttl < 5                              packets about to expire
ip.flags.mf == 1 or ip.frag_offset > 0  fragments
ip.addr == 192.0.2.0/24                 a whole subnet
ip.dst == 224.0.0.0/4                   multicast

Add the ip.ttl and ip.id columns when investigating odd traffic. A host whose TTL changes between packets, or that sends the same ip.id for many packets, may be behind NAT or a load balancer.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A packet arrives with TTL 57. What is the most reasonable guess about its origin?

    Common initial TTLs are 64, 128 and 255; 57 is just under 64, so around 7 hops were crossed. It is a hint, not proof.
  2. 2. A router receives a packet with DF set that is larger than the next link's MTU. What happens?

    With DF set the packet may not be fragmented, so the router reports the problem and includes the next-hop MTU.
  3. 3. How does traceroute discover each router on the path?

    A router that sets the TTL to zero returns an ICMP time exceeded message from its own address.
  4. 4. Why must a router recompute the IP header checksum?

    The header checksum covers the TTL, which every router decrements.

Summary

  • The IPv4 header carries addresses, TTL, protocol number, flags and fragmentation fields.
  • TTL values hint at the origin and hop count; expiry produces ICMP time exceeded (type 11).
  • Large packets with DF set need ICMP type 3 code 4 to work with path MTU discovery.
  • ICMP types and codes identify ping, unreachable destinations, redirects and traceroute hops.
  • Blocking all ICMP breaks useful mechanisms such as path MTU discovery.

Next: TCP: Handshake and Sequence Numbers