IPv4 & IPv6 Addressing
Layer 3 defines logical addressing and routing. Understanding IP headers, subnetting, and MTU is critical for network engineering.
1. The IPv4 Header
The standard IPv4 header is 20 bytes (without options). Routers process this header to make forwarding decisions based on the Destination IP.
- TTL (Time To Live): Decremented by 1 at every router hop. Prevents infinite loops. When it hits 0, the router sends an ICMP "Time Exceeded" message.
- Protocol Field: Tells IP what payload is inside.
1: ICMP6: TCP17: UDP89: OSPF
2. Historical Context: Classful Addressing
Before CIDR (1993), IP addresses were divided into strict "Classes" based on the first octet. This wasted millions of addresses.
- Class A (0-127):
/8(16M hosts). Only 126 networks existed. (e.g., Apple, IBM, MIT). - Class B (128-191):
/16(65k hosts). Too big for most companies. - Class C (192-223):
/24(254 hosts). Too small.
Subnetting & CIDR Cheat Sheet
CIDR (Classless Inter-Domain Routing) allows variable-length subnet masks (VLSM), breaking the rigid class structure.
RFC 1918 Private Address Space
These ranges are not routable on the public Internet. NAT (Network Address Translation) is required.
- Class A:
10.0.0.0/8(10.0.0.0 - 10.255.255.255) - Class B:
172.16.0.0/12(172.16.0.0 - 172.31.255.255) - Class C:
192.168.0.0/16(192.168.0.0 - 192.168.255.255)
IPv6 Address Types
- Global Unicast (2000::/3): Publicly routable (like IPv4 Public IP).
- Link-Local (FE80::/10): Only valid on the local segment. Used for neighbor discovery and routing protocol hellos. (Always exists!).
- Unique Local (FC00::/7): Private use (like IPv4 RFC 1918).
- Multicast (FF00::/8): One-to-Many.
| CIDR | Subnet Mask | Hosts | Magic Number (Block Size) |
|---|---|---|---|
| /24 | 255.255.255.0 | 254 | 1 (in 3rd octet) |
| /25 | 255.255.255.128 | 126 | 128 |
| /26 | 255.255.255.192 | 62 | 64 |
| /27 | 255.255.255.224 | 30 | 32 |
| /28 | 255.255.255.240 | 14 | 16 |
| /29 | 255.255.255.248 | 6 | 8 |
| /30 | 255.255.255.252 | 2 | 4 (Common for P2P links) |
| /32 | 255.255.255.255 | 1 | 1 (Host route) |
Historically, /30 was the standard for point-to-point links (4 IPs, 2 usable). Modern routers support /31 (2 IPs total, both usable as host addresses) to conserve address space on P2P links. RFC 3021.
3. MTU & Fragmentation
MTU (Maximum Transmission Unit) is typically 1500 bytes for Ethernet. If a packet is larger than the MTU:
- If DF (Don't Fragment) bit is Set: The router drops the packet and sends ICMP Type 3 Code 4 ("Fragmentation Needed").
- If DF is Clear: The router fragments the packet, increasing CPU load and overhead.
Path MTU Discovery (PMTUD) relies on ICMP. If you block all ICMP at your firewall, PMTUD breaks, causing "black hole" connections where small packets pass but large ones (like HTTP responses) fail.