Skip to main content
IPv4/IPv6 Addressing & CIDR Subnetting
Lesson 2 of 7

IPv4/IPv6 Addressing & CIDR Subnetting

Explain IPv4 and IPv6 packet forwarding, calculate CIDR subnets, read Linux routing tables, and defend against Layer 3 and supporting protocol attacks.

Beginner 30 min Networking
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Explain how IPv4 and IPv6 packets are structured, forwarded, and protected from routing loops
  • Calculate usable host counts and network boundaries using CIDR subnet notation
  • Interpret a Linux routing table and trace how static and dynamic routing select a next hop
  • Identify how ICMP, ARP, DNS, and DHCP support IP networking and defend against their abuse

Recommended first: OSI and TCP/IP Reference Models

#Why this matters

Switches move frames inside one local VLAN, but they cannot forward traffic across separate networks. That role belongs to the Network Layer (OSI Layer 3), where routers inspect logical IP addresses and forward packets hop by hop.

Understanding IP headers, CIDR subnets, and routing tables is essential for defenders. Misconfigured routes expose internal segments, overly wide subnets expand the attack surface, and Layer 3 blind spots enable source spoofing, cache poisoning, and route hijacking.

#IPv4 and IPv6 packet design

The Internet Protocol (IP) is connectionless (each packet is routed independently) and best-effort (it does not guarantee ordered delivery or retransmission). Higher-layer protocols such as TCP provide reliability. Standard IP also lacks built-in source authentication, which makes IP spoofing possible without edge filtering.

An IPv4 header (20 to 60 bytes) carries Version, Header Length (IHL), Total Length (up to 65,535 bytes), Identification, Flags, Fragment Offset, Time to Live (TTL), Protocol (TCP = 6, UDP = 17, ICMP = 1), Header Checksum, and 32-bit Source and Destination addresses. When a packet exceeds a link's MTU (typically 1500 bytes), IPv4 splits it into fragments. Each router decrements the 8-bit TTL by 1; when TTL reaches 0, the router drops the packet and returns ICMP Time Exceeded, preventing infinite routing loops.

IPv6 replaces 32-bit addresses with 128-bit hexadecimal addresses (such as 2001:db8:10::1) and uses a fixed 40-byte header with Hop Limit instead of TTL, no header checksum, no router-side fragmentation, and Neighbor Discovery Protocol (NDP) over ICMPv6 instead of ARP.

IPv4 vs IPv6
IPv4
  • 32-bit dotted-decimal addresses
  • Variable 20-60 byte header with checksum
  • Routers may fragment oversized packets
  • Uses TTL (8-bit) and ARP on LANs
IPv6
  • 128-bit hexadecimal addresses
  • Fixed 40-byte header without checksum
  • Only senders fragment via Path MTU Discovery
  • Uses Hop Limit (8-bit) and NDP over ICMPv6

#CIDR subnetting and address planning

Classless Inter-Domain Routing (CIDR) replaced legacy classful networks (Class A, B, C) by appending a prefix length such as /24. The prefix bits identify the network; the remaining bits identify hosts.

Usable IPv4 hosts in a standard subnet equal 2^(32 - prefix) - 2 (subtracting the network and broadcast addresses), except /32 single-host routes and RFC 3021 /31 links.

CIDR Subnet mask Usable hosts Typical use
/8 255.0.0.0 16,777,214 Large private block (legacy Class A)
/16 255.255.0.0 65,534 Large campus (legacy Class B)
/24 255.255.255.0 254 Standard office or lab LAN (legacy Class C)
/30 255.255.255.252 2 Point-to-point router link
/32 255.255.255.255 1 Single host route or firewall rule

Private RFC 1918 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) operate inside local networks behind NAT, while documentation blocks like 192.0.2.0/24 are reserved for lab examples.

#Routing tables and dynamic protocols

Routers forward packets using longest-prefix match, choosing the most specific matching CIDR route and falling back to the default route 0.0.0.0/0 (or ::/0) when nothing more specific matches.

  1. Packet arrivesRead destination IP and decrement TTL
  2. Longest prefix matchPick most specific route or default route
  3. Resolve next hopLook up neighbor MAC via ARP or NDP
  4. Forward frameSend out chosen network interface

Static routing is configured manually: simple and lightweight, but inflexible during link failures. Dynamic routing adapts automatically: RIP is an older legacy protocol, OSPF is the standard interior protocol for enterprise networks, and BGP is the main routing protocol across the internet.

Inspecting routes and neighbors on a Linux lab host
$ ip route show
default via 10.10.10.1 dev eth0
10.10.10.0/24 dev eth0 proto kernel scope link src 10.10.10.15
192.0.2.0/24 via 10.10.10.254 dev eth1
$ ip neigh show
10.10.10.1 dev eth0 lladdr 00:53:00:11:22:33 REACHABLE

#Supporting protocols: ICMP, ARP, DNS, and DHCP

Four companion protocols keep IP networks running (not all reside strictly at Layer 3):

  • ICMP (Layer 3): Delivers error and diagnostic messages. ping uses Echo Request/Reply; traceroute increments TTL to trigger Time Exceeded replies.
  • ARP (Layer 2/3 bridge): Resolves an IPv4 address to a MAC address on a LAN (viewed with ip neigh or arp -a).
  • DNS (Layer 7, UDP/TCP 53): Maps domain names like lab.local to IP addresses.
  • DHCP (Layer 7, UDP 67/68): Assigns IPs automatically via DORA: Discover (broadcast), Offer, Request, and ACK.

#Defending / Common mistakes

  • IP spoofing and fragmentation: Forged source IPs enable reflection attacks, while malformed fragments (such as historic Teardrop attacks) targeted OS reassembly bugs. Enforce ingress filtering (BCP 38) at network edges and deploy IPsec for Layer 3 encryption and authentication.
  • ICMP abuse: Smurf broadcast floods, Ping of Death, and ICMP floods waste bandwidth. Disable directed broadcasts and rate-limit ICMP instead of blocking all types blindly.
  • ARP poisoning and Rogue DHCP: Forged ARP replies redirect LAN traffic to an attacker's MAC for MITM interception; Rogue DHCP servers answer Discover broadcasts with malicious gateways or DNS, and DHCP starvation drains pools. Enable Dynamic ARP Inspection (DAI), DHCP snooping, or static ARP for critical gateways.
  • BGP hijacking and DNS tampering: Protect BGP with RPKI route validation, sign DNS zones with DNSSEC to stop spoofing and cache poisoning, and close open recursive resolvers against DNS amplification.

#Summary

  • IPv4 and IPv6 provide connectionless, best-effort Layer 3 forwarding, dropping looping packets when TTL or Hop Limit hits 0.
  • CIDR defines subnet sizes flexibly (2^(32 - prefix) - 2 usable IPv4 hosts: 254 for /24, 2 for /30).
  • Routers select paths by longest-prefix match using static routes, OSPF inside enterprises, and BGP across the internet.
  • Defend IP and helper protocols (ICMP, ARP, DNS, DHCP) with ingress filtering, IPsec, DAI, DHCP snooping, RPKI, and DNSSEC.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in