Part I: Network Theory Chapter 4

Internet Protocol (IP)

IPv4 addressing, subnetting, CIDR, IPv6 adoption, ICMP, and dual-stack scenarios

Chapter 4: Internet Protocol (IP)

The Day 3.4 Billion Addresses Weren’t Enough

On February 3, 2011, IANA (the Internet Assigned Numbers Authority) allocated the last blocks of IPv4 addresses to the five Regional Internet Registries. After nearly 30 years, the internet had exhausted its 4.3 billion IPv4 addresses.

The prediction had been made years earlier. In 1992, with only 3% of addresses allocated, experts projected exhaustion within a decade. They were roughly right. The response was IPv6, designed in 1995 with 340 undecillion addresses (3.4 Γ— 10^38)β€”enough to give every atom on Earth its own address. Surely that would be enough.

Yet here we are, decades later, and IPv4 still dominates. Why? Because NAT (Network Address Translation) extended IPv4’s life dramatically, allowing millions of devices to hide behind single public IPs. IPv6 adoption, while growing, remains incomplete. Today’s network professional must master both protocols and understand how they coexistβ€”sometimes elegantly, sometimes awkwardly.

This chapter explores IP addressing, subnetting, the transition to IPv6, and ICMPβ€”the protocol that reports when things go wrong.


The Network Layer: Beyond the Local Network

In Chapter 3, we explored how data travels within a local network using MAC addresses and Ethernet frames. But the internet isn’t one big local networkβ€”it’s millions of networks interconnected worldwide. When you send data to a server across the globe, that data traverses many different networks, each with its own Layer 2 technology.

The Internet Protocol (IP) solves this challenge by providing:

  • Universal addressing: IP addresses identify devices globally (or within an organization)
  • Routing foundation: Routers use IP addresses to forward packets hop by hop toward their destination
  • Technology independence: IP works over any Layer 2 technologyβ€”Ethernet, WiFi, cellular, satellite

This layer of abstractionβ€”logical addresses independent of physical hardwareβ€”is what makes the internet possible.


IPv4: The Workhorse of the Internet

IPv4 Address Structure

An IPv4 address is a 32-bit number, providing approximately 4.3 billion unique addresses (2^32). While that seemed enormous in the 1980s, it proved insufficient for the modern worldβ€”leading to the development of IPv6. Nevertheless, IPv4 remains the backbone of most networks today.

IPv4 addresses are written in dotted decimal notation: four decimal numbers (0-255) separated by dots, each representing 8 bits (one octet).

IPv4 Address Structure

IPv4 Address Structure:
═══════════════════════════════════════════════════════════════════

IPv4 Address: 192.168.1.100

Dotted Decimal:    192    .   168    .    1      .    100
                    β”‚          β”‚          β”‚            β”‚
Binary:         11000000   10101000   00000001   01100100
                    β”‚          β”‚          β”‚            β”‚
                 8 bits     8 bits     8 bits      8 bits
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              32 bits total

Each octet ranges from 0 (00000000) to 255 (11111111)

Network and Host Portions

Every IP address has two components:

  • Network portion: Identifies which network the device belongs to
  • Host portion: Identifies the specific device within that network

The division between network and host portions is determined by the subnet mask.

Network vs Host Portions

Network vs Host Portions:
═══════════════════════════════════════════════════════════════════

IP Address:    192.168.1.100
Subnet Mask:   255.255.255.0

Binary breakdown:
IP:     11000000.10101000.00000001.01100100
Mask:   11111111.11111111.11111111.00000000
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              Network portion      Host portion
              (where mask = 1)    (where mask = 0)

Network Address: 192.168.1.0   (all host bits = 0)
Broadcast Address: 192.168.1.255 (all host bits = 1)
Usable Host Range: 192.168.1.1 - 192.168.1.254

All devices with IPs in 192.168.1.x are on the same network

PRO TIP

The network address (all host bits 0) and broadcast address (all host bits 1) are reserved and cannot be assigned to devices. This is why a /24 network has 254 usable addresses, not 256.

CIDR Notation

CIDR (Classless Inter-Domain Routing) provides a compact way to specify the subnet mask by indicating how many bits are used for the network portion.

CIDR Notation

CIDR Notation:
═══════════════════════════════════════════════════════════════════

192.168.1.100/24

The /24 means:
β”œβ”€β”€ First 24 bits are the network portion
β”œβ”€β”€ Remaining 8 bits (32-24) are the host portion
└── Equivalent to subnet mask 255.255.255.0

Converting CIDR to Subnet Mask:
/8  β†’ 255.0.0.0       (11111111.00000000.00000000.00000000)
/16 β†’ 255.255.0.0     (11111111.11111111.00000000.00000000)
/24 β†’ 255.255.255.0   (11111111.11111111.11111111.00000000)
/25 β†’ 255.255.255.128 (11111111.11111111.11111111.10000000)
/30 β†’ 255.255.255.252 (11111111.11111111.11111111.11111100)

Common CIDR ranges:

CIDRSubnet MaskTotal IPsUsable HostsTypical Use
/8255.0.0.016,777,21616,777,214Large ISPs, cloud providers
/16255.255.0.065,53665,534Large enterprises
/24255.255.255.0256254Small networks, home LANs
/27255.255.255.2243230Small subnets
/30255.255.255.25242Point-to-point links
/31255.255.255.25422Point-to-point (RFC 3021)
/32255.255.255.25511Single host route

Subnetting

Subnetting divides a larger network into smaller subnetworks. This provides:

  • Better organization and management
  • Reduced broadcast traffic (broadcasts don’t cross subnets)
  • Improved security (traffic between subnets can be controlled)
  • More efficient IP address allocation

Subnetting Example

Subnetting Example:
═══════════════════════════════════════════════════════════════════

Given: 192.168.1.0/24 - Need to create 4 subnets

Original: 192.168.1.0/24 (254 hosts)

Borrow 2 bits from host portion (/24 β†’ /26):

Subnet 1: 192.168.1.0/26    (192.168.1.1 - 192.168.1.62)    62 hosts
Subnet 2: 192.168.1.64/26   (192.168.1.65 - 192.168.1.126)  62 hosts
Subnet 3: 192.168.1.128/26  (192.168.1.129 - 192.168.1.190) 62 hosts
Subnet 4: 192.168.1.192/26  (192.168.1.193 - 192.168.1.254) 62 hosts

Visual breakdown:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     192.168.1.0/24                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  .0/26         β”‚  .64/26        β”‚  .128/26       β”‚  .192/26     β”‚
β”‚  Engineering   β”‚  Sales         β”‚  HR            β”‚  Guest       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

TRY IT YOURSELF

Practice subnetting with this exercise: Given 10.0.0.0/8, create subnets for:

  • Data Center: Needs 500 hosts
  • Office A: Needs 100 hosts
  • Office B: Needs 50 hosts
  • Management: Needs 10 hosts

What CIDR blocks would you assign to each?

Special IPv4 Addresses

Certain address ranges have special meanings:

Address/RangePurposeNotes
0.0.0.0/8This networkUsed during boot (DHCP)
10.0.0.0/8Private (Class A)16M+ addresses
127.0.0.0/8Loopbacklocalhost (127.0.0.1)
169.254.0.0/16Link-local (APIPA)Auto-assigned when no DHCP
172.16.0.0/12Private (Class B range)172.16.0.0 - 172.31.255.255
192.168.0.0/16Private (Class C range)Most common home networks
224.0.0.0/4Multicast224.0.0.0 - 239.255.255.255
240.0.0.0/4ReservedHistorically β€œClass E”
255.255.255.255Limited broadcastLocal network only

Private addresses (RFC 1918) are not routable on the public internet. They’re used within organizations and homes, with NAT providing internet access. This greatly extended the life of IPv4 by allowing millions of private networks to share public addresses.

Private Address Ranges

Private Address Ranges:
═══════════════════════════════════════════════════════════════════

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Range           β”‚ CIDR                     β”‚ # of Addresses    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 10.0.0.0 -      β”‚ 10.0.0.0/8               β”‚ 16,777,216        β”‚
β”‚ 10.255.255.255  β”‚                          β”‚ (One Class A)     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 172.16.0.0 -    β”‚ 172.16.0.0/12            β”‚ 1,048,576         β”‚
β”‚ 172.31.255.255  β”‚                          β”‚ (16 Class Bs)     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 192.168.0.0 -   β”‚ 192.168.0.0/16           β”‚ 65,536            β”‚
β”‚ 192.168.255.255 β”‚                          β”‚ (256 Class Cs)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

These addresses can be used by anyone internally
They CANNOT be routed on the public internet

Security Note: Understanding private vs. public addresses is crucial for security. Internal network reconnaissance often reveals private addresses that indicate network structure. Improperly configured NAT or firewalls can expose internal addresses. See Part II, Chapter 9 for reconnaissance techniques.

The IPv4 Header

The IPv4 header contains all the information routers need to forward packets. Understanding its structure helps in packet analysis and crafting.

IPv4 Header Format (20 bytes minimum, up to 60 with options)

IPv4 Header Format (20 bytes minimum, up to 60 with options):
═══════════════════════════════════════════════════════════════════

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
β”œβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”€
β”‚Versionβ”‚  IHL  β”‚   DSCP    β”‚ECNβ”‚         Total Length          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Identification        β”‚Flagsβ”‚      Fragment Offset    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚      TTL      β”‚   Protocol    β”‚        Header Checksum        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                       Source IP Address                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Destination IP Address                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Options (if IHL > 5)                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key fields:

FieldSizeDescription
Version4 bitsIP version (4 for IPv4)
IHL4 bitsHeader length in 32-bit words (min 5 = 20 bytes)
DSCP/ECN8 bitsQoS markings and congestion notification
Total Length16 bitsEntire packet size in bytes (max 65,535)
Identification16 bitsFragment identification
Flags3 bitsDF (Don’t Fragment), MF (More Fragments)
Fragment Offset13 bitsPosition in fragmented packet
TTL8 bitsMaximum hops before discard (0-255)
Protocol8 bitsUpper layer protocol (6=TCP, 17=UDP, 1=ICMP)
Header Checksum16 bitsError detection for header only
Source IP32 bitsSender’s IP address
Destination IP32 bitsRecipient’s IP address

Time to Live (TTL): TTL prevents packets from looping forever. Each router decrements TTL by 1; when it reaches 0, the packet is discarded and an ICMP β€œTime Exceeded” message is sent. This is how traceroute worksβ€”it sends packets with increasing TTL values to discover the path.

TTL in Action

TTL in Action:
═══════════════════════════════════════════════════════════════════

Packet starts with TTL=64

[Source] ──► [Router 1] ──► [Router 2] ──► [Router 3] ──► [Dest]
  TTL=64      TTL=63         TTL=62         TTL=61

Common default TTL values:
Linux/Unix: 64
Windows: 128
Cisco: 255

Security implication: TTL can help identify OS (fingerprinting)

Security Note: The source IP address can be forged (IP spoofing). IP has no built-in authentication mechanism. This enables various attacks including denial of service with spoofed sources and certain MITM scenarios. See Part II, Chapter 3.

IP Fragmentation

If a packet is larger than the Maximum Transmission Unit (MTU) of a network link (typically 1500 bytes for Ethernet), it must be fragmented into smaller pieces. The receiving host reassembles the fragments.

IP Fragmentation

IP Fragmentation:
═══════════════════════════════════════════════════════════════════

Original Packet (4000 bytes data):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ IP Header β”‚                     Data (4000 bytes)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

After fragmentation for MTU 1500:

Fragment 1 (1500 bytes):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚IP Header β”‚    Data (1480 bytes)                    β”‚ MF=1
β”‚ID=12345  β”‚    Offset=0                             β”‚ Offset=0
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Fragment 2 (1500 bytes):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚IP Header β”‚    Data (1480 bytes)                    β”‚ MF=1
β”‚ID=12345  β”‚    Offset=1480                          β”‚ Offset=185
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Fragment 3 (1060 bytes):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚IP Header β”‚    Data (1040 bytes)    β”‚               β”‚ MF=0
β”‚ID=12345  β”‚    Offset=2960          β”‚               β”‚ Offset=370
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Fragmentation fields:
- Identification: Same value (12345) for all fragments
- More Fragments (MF): 1 if more coming, 0 for last
- Fragment Offset: Position in original packet (Γ·8)

** COMMON MISTAKE**

Fragment offset is in 8-byte units, not bytes. So offset=185 means byte position 1480 (185 Γ— 8).

Security Note: Fragmentation has been exploited in attacks like the β€œPing of Death” (oversized ping causing buffer overflow) and β€œTeardrop” (overlapping fragments causing crashes). Modern systems are patched against these classic attacks, but fragmentation-based evasion of security devices remains relevant. See Part II, Chapter 3.


IPv6: The Next Generation

Why IPv6?

IPv4’s 4.3 billion addresses seemed inexhaustible in the early internet days. As the internet grew exponentially, address exhaustion became a real crisis. NAT extended IPv4’s life, but introduced complexity and broke the end-to-end connectivity model.

IPv6 addresses this with 128-bit addressesβ€”providing 3.4 Γ— 10^38 unique addresses. That’s roughly 340 undecillion, or enough to assign an IP to every grain of sand on Earth.

IPv6 Address Format

IPv6 addresses are written as eight groups of four hexadecimal digits, separated by colons:

IPv6 Address Format

IPv6 Address Format:
═══════════════════════════════════════════════════════════════════

Full IPv6 address (128 bits):
  2001  : 0db8  : 85a3  : 0000  : 0000  : 8a2e  : 0370  : 7334
β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜β””β”€β”€β”¬β”€β”€β”€β”˜
  16bit  16bit  16bit  16bit  16bit  16bit  16bit  16bit
                    8 groups Γ— 16 bits = 128 bits

Simplification rules:
1. Remove leading zeros in each group:
   2001:0db8:85a3:0000:0000:8a2e:0370:7334
   β†’ 2001:db8:85a3:0:0:8a2e:370:7334

2. Replace ONE consecutive group of all zeros with ::
   2001:db8:85a3:0:0:8a2e:370:7334
   β†’ 2001:db8:85a3::8a2e:370:7334
   
   (:: can only be used ONCE per address)

Examples:
Full:       2001:0db8:0000:0000:0000:0000:0000:0001
Simplified: 2001:db8::1

Loopback:
Full:       0000:0000:0000:0000:0000:0000:0000:0001
Simplified: ::1

IPv6 Address Types

TypePrefixDescriptionExample
Global Unicast2000::/3Publicly routable (like public IPv4)2001:db8::1
Link-Localfe80::/10Auto-configured, single link onlyfe80::1
Unique Localfc00::/7Private addresses (like RFC 1918)fd00::1
Multicastff00::/8One-to-many deliveryff02::1
Loopback::1/128Localhost::1
Unspecified::/128Like 0.0.0.0 in IPv4::

IPv6 Address Types Visual

IPv6 Address Types Visual:
═══════════════════════════════════════════════════════════════════

Global Unicast (2000::/3) - Internet routable
β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 001 β”‚ Global Routing Prefix β”‚ Subnet ID β”‚    Interface ID      β”‚
β”‚3 bitβ”‚      45 bits          β”‚  16 bits  β”‚      64 bits         β”‚
β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Link-Local (fe80::/10) - Local network only, auto-generated
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 1111111010 β”‚        0        β”‚         Interface ID            β”‚
β”‚   10 bits  β”‚     54 bits     β”‚           64 bits               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
fe80::MAC-derived-ID

Every IPv6 interface has a link-local address automatically!

IPv6 Header

IPv6 simplified the header compared to IPv4:

IPv6 Header Format (40 bytes fixed)

IPv6 Header Format (40 bytes fixed):
═══════════════════════════════════════════════════════════════════

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
β”œβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”Όβ”€β”€
β”‚Versionβ”‚ Traffic Class β”‚              Flow Label               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚      Payload Length   β”‚  Next Header  β”‚      Hop Limit        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                               β”‚
β”‚                     Source Address (128 bits)                 β”‚
β”‚                                                               β”‚
β”‚                                                               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                               β”‚
β”‚                  Destination Address (128 bits)               β”‚
β”‚                                                               β”‚
β”‚                                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key differences from IPv4:

  • No header checksum: Relies on Layer 2 and Layer 4 checksums (faster processing)
  • No fragmentation fields: Fragmentation handled by source only (Path MTU Discovery)
  • Fixed 40-byte header: Simpler processing
  • Next Header field: Allows extension headers for optional features
  • Flow Label: Can identify traffic flows for QoS

IPv6 Neighbor Discovery Protocol (NDP)

IPv6 replaces ARP with Neighbor Discovery Protocol (NDP), which uses ICMPv6:

NDP Functions (ICMPv6)

NDP Functions (ICMPv6):
═══════════════════════════════════════════════════════════════════

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Function              β”‚ IPv4 Equivalent β”‚ ICMPv6 Type          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Router Solicitation   β”‚ N/A             β”‚ Type 133             β”‚
β”‚ Router Advertisement  β”‚ DHCP (partial)  β”‚ Type 134             β”‚
β”‚ Neighbor Solicitation β”‚ ARP Request     β”‚ Type 135             β”‚  
β”‚ Neighbor Advertisementβ”‚ ARP Reply       β”‚ Type 136             β”‚
β”‚ Redirect              β”‚ ICMP Redirect   β”‚ Type 137             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Neighbor Solicitation Example (Like ARP):
─────────────────────────────────────────

Host A wants to reach Host B (2001:db8::2)

[Host A]                                           [Host B]
    β”‚                                                  β”‚
    β”‚  Neighbor Solicitation                           β”‚
    β”‚  "Who has 2001:db8::2?"                          β”‚
    β”‚  Dst: ff02::1:ff00:0002 (solicited-node mcast)   β”‚
    β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚
    β”‚                                                  β”‚
    β”‚  Neighbor Advertisement                          β”‚
    β”‚  "2001:db8::2 is at MAC xx:xx:xx:xx:xx:xx"       β”‚
    │◄──────────────────────────────────────────────────
    β”‚                                                  β”‚

Security Note: NDP has similar vulnerabilities to ARPβ€”spoofing attacks are possible. Secure Neighbor Discovery (SEND) was designed to address this but is rarely deployed. RA Guard and ND Inspection provide practical mitigations.

IPv6 Security Considerations

IPv6 was designed with security in mind:

  • IPsec support: Originally mandatory, now recommended
  • No broadcast: Uses multicast instead, reducing certain attack surfaces
  • Larger address space: Harder to scan (2^64 addresses per subnet!)

However, IPv6 introduces new security considerations:

ConcernDescriptionMitigation
Dual-stackRunning both IPv4 and IPv6 doubles attack surfaceMonitor both protocols
Security tool maturityMany tools focus on IPv4Ensure IPv6 visibility
Extension headersCan be used to evade firewallsDeep packet inspection
Privacy extensionsRandomized addresses can help or hinderUnderstand your environment
Rogue RAFake router advertisementsRA Guard
NDP spoofingLike ARP spoofingND Inspection

IPv6 Transition Mechanisms

The internet is slowly transitioning from IPv4 to IPv6. Several mechanisms facilitate coexistence:

Dual Stack: Devices run both IPv4 and IPv6 simultaneously

Application

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Application                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        IPv4          β”‚           IPv6              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Network Interface               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tunneling: IPv6 packets encapsulated in IPv4 for transport across IPv4-only networks

  • 6to4, 6rd, ISATAP, Teredo (mostly deprecated)
  • IPv6 over IPv4 GRE tunnels (still common)

Translation: Converting between IPv4 and IPv6 at network boundaries

  • NAT64/DNS64: Allow IPv6-only hosts to reach IPv4 servers
  • SIIT: Stateless IP/ICMP Translation

Security Note: Transition mechanisms introduce complexity and potential vulnerabilities. Tunneled traffic may bypass IPv4 security controls. Security teams must monitor both protocol versions.


ICMP: The Network’s Diagnostic Tool

What ICMP Does

The Internet Control Message Protocol (ICMP) is IP’s companion for error reporting and diagnostics. When something goes wrong in IP communicationβ€”a host is unreachable, a packet’s TTL expires, or a route doesn’t existβ€”ICMP delivers the bad news.

ICMP is also the foundation of familiar diagnostic tools like ping and traceroute.

ICMP Message Types

TypeCodeDescriptionUse
00Echo ReplyPing response
30Network UnreachableRouting failure
31Host UnreachableHost offline/filtered
33Port UnreachableService not running
34Fragmentation NeededMTU issue (Path MTU Discovery)
313Communication Administratively ProhibitedFirewall blocked
5xRedirectUse a different route
80Echo RequestPing
110TTL Exceeded in TransitTraceroute
111Fragment Reassembly Time ExceededFragment timeout

Ping: Echo Request/Reply

The ping utility sends ICMP Echo Request messages and listens for Echo Replies:

$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=117 time=15.4 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=14.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=15.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=15.0 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 14.9/15.1/15.4/0.2 ms

What ping tells you:

  • Host is reachable (or not)
  • Round-trip time (latency)
  • Packet loss percentage
  • TTL value (hints at hop count, OS fingerprint)

Traceroute: Mapping the Path

traceroute exploits TTL to discover the path packets take:

Traceroute Mechanism

Traceroute Mechanism:
═══════════════════════════════════════════════════════════════════

1. Send packet with TTL=1
   β†’ First router decrements to 0, sends ICMP TTL Exceeded
   
2. Send packet with TTL=2
   β†’ First router decrements to 1, forwards
   β†’ Second router decrements to 0, sends ICMP TTL Exceeded
   
3. Continue until destination responds or max hops reached

Example output:
$ traceroute google.com
traceroute to google.com (142.250.80.46), 30 hops max
 1  192.168.1.1 (192.168.1.1)  1.234 ms  0.987 ms  1.001 ms
 2  10.0.0.1 (10.0.0.1)  8.432 ms  8.234 ms  8.567 ms
 3  72.14.215.85 (72.14.215.85)  9.123 ms  9.234 ms  9.111 ms
 4  * * *                         ← Router didn't respond (filtered)
 5  142.250.80.46 (142.250.80.46)  10.234 ms  10.111 ms  10.345 ms

Note: * * * indicates a hop that didn’t respondβ€”often firewalls blocking ICMP or routers configured not to respond.

PRO TIP

Different traceroute tools use different protocols:

  • traceroute (Linux/macOS): UDP by default
  • traceroute -I (Linux): ICMP
  • tracert (Windows): ICMP
  • traceroute -T (Linux): TCP (often works when others are blocked)

ICMP Security Considerations

ICMP is essential for network operation but presents security risks:

Reconnaissance:

  • Ping sweeps identify live hosts
  • Traceroute reveals network topology
  • ICMP responses can fingerprint operating systems
  • Destination Unreachable messages reveal firewall rules

Attacks:

  • Smurf Attack: Spoofed ping to broadcast address causes amplification
  • Ping of Death: Oversized ping causing buffer overflow (historical)
  • ICMP Tunneling: Hiding data in ICMP payloads to bypass firewalls
  • ICMP Redirect Attacks: Malicious redirect messages altering routing
  • Flood attacks: ICMP flood can overwhelm targets

Smurf Attack (Historical)

Smurf Attack (Historical):
═══════════════════════════════════════════════════════════════════

                         Attacker
                            β”‚
    1. ICMP Echo Request    β”‚   Source: Victim's IP (spoofed)
       to broadcast         β”‚   Destination: 192.168.1.255
       192.168.1.255        β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   Network     β”‚
                    β”‚  (100 hosts)  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
    2. All 100 hosts        β”‚
       send ICMP Echo       β”‚
       Reply to victim      β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    Victim     β”‚  ← Flooded with 100 replies
                    β”‚               β”‚     for every 1 request
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Amplification factor: 100x (or more on larger networks)
Mitigation: Disable directed broadcast (default on modern routers)

Security Note: Many organizations filter ICMP at network boundaries. While this improves security, it can break legitimate diagnostics and Path MTU Discovery. ICMP-based attacks are detailed in Part II, Chapter 3.

ICMPv6

IPv6 has its own ICMP version (ICMPv6, protocol number 58) that’s more integral to IPv6 operation:

  • Neighbor Discovery: Replaces ARP, discovers other nodes on the link
  • Router Discovery: Finds routers and obtains configuration
  • Path MTU Discovery: Determines optimal packet size
  • Multicast Listener Discovery: IPv6 multicast management

ICMPv6 cannot be completely blocked without breaking IPv6 functionality.


Practical Commands

# View IP configuration
ip addr                     # Linux
ifconfig                    # macOS/older Linux
ipconfig /all               # Windows

# View routing table
ip route                    # Linux
netstat -rn                 # macOS/older Linux
route print                 # Windows

# Test connectivity
ping <host>
ping -c 4 8.8.8.8           # Linux/macOS (4 packets)
ping -n 4 8.8.8.8           # Windows (4 packets)
ping6 <ipv6_host>           # IPv6 ping

# Trace route
traceroute <host>           # macOS/Linux (uses UDP)
traceroute -I <host>        # Use ICMP
traceroute -T -p 443 <host> # Use TCP
tracert <host>              # Windows (uses ICMP)

# View neighbor cache (ARP for IPv4, NDP for IPv6)
ip neigh                    # Linux
arp -a                      # All platforms
ndp -a                      # macOS IPv6

# Path MTU discovery
tracepath <host>            # Linux (discovers MTU along path)

# Check your public IP
curl ifconfig.me
curl ipinfo.io

TRY IT YOURSELF

Compare traceroute behavior:

# Standard (UDP)
traceroute google.com

# ICMP (more likely to reach destination)
traceroute -I google.com

# TCP on port 443 (often works through firewalls)
sudo traceroute -T -p 443 google.com

Notice how different protocols may reveal different paths or more hops!


Key Takeaways

  1. IPv4 uses 32-bit addresses written in dotted decimal notation, providing ~4.3 billion addresses

  2. Subnetting divides networks logically using subnet masks; CIDR notation compactly represents this

  3. Private addresses (10.x, 172.16-31.x, 192.168.x) and NAT extend IPv4’s lifespan

  4. IPv6 provides 128-bit addresses, solving address exhaustion with 340 undecillion addresses

  5. The IPv4 header contains routing information including TTL, which prevents infinite loops

  6. ICMP provides diagnostics (ping, traceroute) and error reporting, but can be exploited for reconnaissance and attacks

  7. Dual-stack environments running both IPv4 and IPv6 are common and require security attention for both protocols


Self-Assessment

  1. Comprehension: If you have a /26 network, how many usable host addresses are available? Why?

  2. Application: You can ping a server by IP (8.8.8.8) but not by name (google.com). At which layer is the problem likely occurring?

  3. What if: If IPv6 were universally deployed tomorrow, what network security controls would become obsolete? Which would remain important?


Review Questions

  1. What is the purpose of the subnet mask?
  2. How does NAT allow private addresses to access the internet?
  3. What happens when a packet’s TTL reaches zero?
  4. Why was IPv6 developed, and what are its main advantages?
  5. How could an attacker use ICMP for reconnaissance?
  6. What is the difference between IPv4 ARP and IPv6 NDP?

Key RFCs

  • RFC 791 - Internet Protocol (IPv4)
  • RFC 8200 - Internet Protocol, Version 6 (IPv6) Specification
  • RFC 792 - Internet Control Message Protocol (ICMP)
  • RFC 4443 - ICMPv6 for IPv6 Specification
  • RFC 1918 - Address Allocation for Private Internets
  • RFC 4632 - CIDR: The Internet Address Assignment and Aggregation Plan
  • RFC 4861 - Neighbor Discovery for IPv6