IPv4 Header
Encapsulation and Protocol Data Units (PDUs)
- Concept: As data moves down the OSI model, it is encapsulated with headers (and trailers) specific to each layer.
- PDUs:
- Layer 4: Segment (TCP) or Datagram (UDP) = L4 Header + Data
- Layer 3: Packet = L3 Header (IPv4) + Segment
- Layer 2: Frame = L2 Header + Packet + L2 Trailer
graph TD
Data[Upper Layer Data] --> L4[Layer 4 Header TCP/UDP]
L4 --> Segment[Segment / L4 PDU]
Segment --> L3[Layer 3 Header IPv4]
L3 --> Packet[Packet / L3 PDU]
Packet --> L2[Layer 2 Header & Trailer]
L2 --> Frame[Frame / L2 PDU]
IPv4 Header Fields Overview
The IPv4 header contains critical information used by routers to forward (route) packets to their destination. It is read left to right, top to bottom (bit by bit).
| Field | Length | Purpose & Details |
|---|---|---|
| Version | 4 bits | Identifies the IP version. IPv4 = 4 (0100 in binary). IPv6 = 6 (0110 in binary). Note: IPv5 was an experimental protocol (Internet Stream Protocol) never publicly used. |
| Internet Header Length (IHL) | 4 bits | Indicates the length of the header in 4-byte increments. - Min value: 5 (5 x 4 = 20 bytes, no options).- Max value: 15 (15 x 4 = 60 bytes, meaning 40 bytes of options). |
| DSCP | 6 bits | Differentiated Services Code Point. Used for QoS (Quality of Service) to prioritize delay-sensitive traffic like voice and video. |
| ECN | 2 bits | Explicit Congestion Notification. Signals network congestion without dropping packets. Optional; requires support from both endpoints and network infrastructure. |
| Total Length | 16 bits | Total length of the entire packet (Header + Data) in bytes (not 4-byte increments). - Min: 20 bytes (header only). - Max: 65,535 bytes. |
| Identification | 16 bits | Uniquely identifies the original IP packet. All fragments of the same packet share this value so the receiver can reassemble them. |
| Flags | 3 bits | Controls and identifies fragmentation. - Bit 0: Reserved (always 0).- Bit 1 (DF): Don’t Fragment. If 1, packet cannot be fragmented.- Bit 2 (MF): More Fragments. Set to 1 if more fragments are coming; 0 for the last fragment or unfragmented packets. |
| Fragment Offset | 13 bits | Indicates the position of the fragment within the original unfragmented packet. Allows reassembly even if fragments arrive out of order. |
| Time to Live (TTL) | 8 bits | Prevents infinite routing loops. Decremented by 1 at each router (hop count). Packet is dropped if TTL reaches 0. Originally designed for seconds, but practically acts as a hop count. Recommended default is 64. |
| Protocol | 8 bits | Identifies the encapsulated Layer 4 PDU type. - TCP = 6- UDP = 17- ICMP = 1 (used by ping)- OSPF = 89 |
| Header Checksum | 16 bits | Checks for errors ONLY in the IPv4 header. It does not check the encapsulated data (Layer 4 protocols like TCP/UDP handle data error checking). |
| Source IP | 32 bits | IPv4 address of the sender. |
| Destination IP | 32 bits | IPv4 address of the intended receiver. |
| Options | Variable (0-40 bytes) | Rarely used. If present, the IHL field will be greater than 5. Max length is 320 bits (40 bytes). |
Packet Fragmentation & MTU
- MTU (Maximum Transmission Unit): The maximum payload size a Layer 2 medium can handle. For standard Ethernet, the MTU is 1500 bytes.
- Fragmentation: If an IP packet exceeds the MTU of an outgoing interface, it is broken into smaller fragments.
- Reassembly: Fragments are reassembled by the receiving host, not by intermediate routers.
Wireshark Analysis & CLI Commands
When analyzing packet captures (e.g., using Wireshark) or testing connectivity, specific behaviors of the IPv4 header can be observed using Cisco IOS ping commands.
! Standard ping (Default size is 100 bytes on Cisco IOS)
Router# ping 192.168.1.2
! Large ping (10,000 bytes). Exceeds the 1500-byte Ethernet MTU, causing fragmentation.
! Wireshark will show multiple fragments with the same Identification value and MF (More Fragments) bit set to 1, except for the last fragment.
Router# ping 192.168.1.2 size 10000
! Ping with the Don't Fragment (DF) bit set.
! If the packet size exceeds the MTU and the DF bit is set, the router will drop the packet and the ping will fail.
Router# ping 192.168.1.2 df-bit
Important Comparisons & Misconceptions
| Concept | Common Misconception | Actual Fact |
|---|---|---|
| Header Checksum vs. L4 Checksum | The IPv4 Header Checksum verifies the integrity of the entire packet (header + data). | The IPv4 Header Checksum only verifies the IPv4 header. Layer 4 protocols (TCP/UDP) have their own checksums to verify the encapsulated data. |
| TTL Purpose | TTL limits how long a packet can exist on the network in seconds. | While originally designed to represent a maximum lifetime in seconds, it practically functions as a hop count limit to prevent infinite routing loops. |
| IHL vs. Total Length | Both fields measure length in the same unit. | IHL measures the header length in 4-byte increments. Total Length measures the entire packet length in bytes. |
| Fragmentation Reassembly | Routers reassemble fragmented packets before forwarding them. | Intermediate routers forward fragments independently. Only the receiving host reassembles the fragments using the Identification, Flags, and Fragment Offset fields. |
Summary of Commands
! Standard ICMP Echo Request (100 bytes by default)
Router# ping <destination_ip>
! Extended ping to test MTU and fragmentation (Size in bytes)
Router# ping <destination_ip> size <bytes>
! Extended ping to set the Don't Fragment (DF) bit in the IPv4 header
Router# ping <destination_ip> df-bit