Python · SQL · Web Dev · Java · AI/ML tracks launching soon — your one platform for all of IT

NAT and DHCP

A deep-dive into how NAT stretches IPv4 address space across billions of devices, how DHCP automates address assignment, and the subtle failure modes and security implications lurking beneath both protocols.

22–30 min May 2026

// Chapter 01

The Address Crisis That Never Ended

In 1981, RFC 791 assigned IPv4 its 32-bit address space: 4.29 billion addresses. The designers figured that was plenty — there were fewer than 1,000 machines on ARPANET. They were spectacularly wrong.

By 1990, the internet was growing 20% per month. By 1994, researchers calculated IPv4 exhaustion by 2008 at current allocation rates. Two solutions emerged: a long-term fix (IPv6) and an immediate bandage (NAT). IPv6 was standardized in 1998. NAT was already deployed in 1994. Here we are in 2026, and IPv4 with NAT is still the dominant address scheme in billions of devices.

The bandage became the foundation.

Network Address Translation (NAT) allows an entire private network to share one or a few public IP addresses. The principle: routers rewrite packet headers at the boundary between private and public address space, maintaining a translation table that maps inside addresses to outside addresses and back. From the internet's perspective, all devices behind a NAT share a single identity.

NAT is defined in RFC 2663 (terminology) and RFC 3022 (traditional NAT). It enables three private address ranges defined in RFC 1918 — 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 — to be reused in billions of networks simultaneously without conflict.

◆ Wow:IANA allocated the last IPv4 /8 blocks to Regional Internet Registries in February 2011. APNIC (Asia-Pacific) ran out of general allocation space in April 2011. RIPE NCC (Europe) ran out in September 2012. ARIN (North America) exhausted its pool in September 2015. Yet IPv4 traffic continues to grow — organizations buy, sell, and lease IPv4 addresses on a secondary market where a single /24 block (256 addresses) can sell for $40,000–$60,000.

The RFC 1918 Private Address Space

Three ranges are reserved for private use — never routed on the public internet:

10.0.0.0/8: Class A equivalent — 16,777,216 host addresses. Used by large enterprises and cloud VPCs.

172.16.0.0/12: Covers 172.16.0.0 – 172.31.255.255 — 1,048,576 addresses. Common in medium enterprises.

192.168.0.0/16: 65,536 addresses. The home/SMB standard — virtually every home router defaults to 192.168.1.0/24.

Additionally, 100.64.0.0/10 (RFC 6598) is reserved for Carrier-Grade NAT (CGNAT) — a second layer of NAT where ISPs aggregate multiple customers behind a single public IP, compounding the address translation problem.

// Chapter 02

NAT Types — Static, Dynamic, and PAT

A company has three types of needs: servers that the internet must reach (need a stable public IP), employees who browse the web (just need internet access), and branch offices that need IPv6-only connectivity to reach legacy IPv4 content. Each need calls for a different NAT mechanism.

This is not one protocol — it is a family of address translation techniques that share a common mechanism but differ in mapping permanence, direction, and address ratio.

NAT Type Comparator

Select a NAT type to compare behavior, use cases, and trade-offs.

PAT / NAT Overload(NAPT, IP Masquerade)

TRAFFIC DIRECTION

Inside → Outside only

ADDRESS RATIO

Many inside IP:port ↔ One outside IP + many ports

EXAMPLE TRANSLATION

192.168.x.x:port → 203.0.113.5:ephemeral_port

ADVANTAGES

Single public IP serves entire LAN

Implicit firewall (no inbound)

Standard for home/SMB routers

LIMITATIONS

Breaks protocols needing embedded IPs (FTP active, SIP)

No inbound without port forwarding

Connection tracking memory

PRIMARY USE CASE

Home/office internet access — one ISP-assigned IP shared by all devices. Standard in 99% of deployments.

PAT — How Port Multiplexing Works

PAT (Port Address Translation) — also called NAT Overload or IP Masquerade — is the most widely deployed form of NAT. It allows thousands of inside hosts to share a single public IP by differentiating flows using transport layer port numbers.

The NAT router maintains a connection tracking table mapping (inside_ip, inside_port, protocol)(outside_ip, outside_port). When a packet arrives from the inside:

1. Router looks up the source IP:port in the NAT table. If no entry, creates one, assigning an available ephemeral port from the router's public IP.

2. Router rewrites the source IP to the public IP and the source port to the assigned port.

3. Router forwards the packet. When the reply arrives at the public IP and assigned port, the router reverses the translation.

# Cisco IOS PAT configuration
! Define inside interface (private side)
interface GigabitEthernet0/0
  ip address 192.168.1.1 255.255.255.0
  ip nat inside

! Define outside interface (public side)
interface GigabitEthernet0/1
  ip address 203.0.113.5 255.255.255.252
  ip nat outside

! Define which inside traffic gets translated
access-list 1 permit 192.168.0.0 0.0.255.255

! Enable PAT (overload = PAT mode)
ip nat inside source list 1 interface GigabitEthernet0/1 overload

! Verify
show ip nat translations                   ! Live translation table
show ip nat translations verbose           ! With timing info
show ip nat statistics                     ! Hit counts, miss counts, translation table size
⚠ Warning:The NAT translation table has a maximum size and per-entry timeouts. TCP entries default to 86400s (24 hours after connection established), but UDP entries expire in 300s. For high-traffic networks, this table can become the bottleneck. Monitor show ip nat statistics for "expired translations" and "max_entries" warnings. Aggressive UDP applications (DNS, video streaming) can exhaust the table if timeouts are too long.

// Chapter 03

The NAT Translation Table in Detail

When you type a URL in your browser, six to twenty separate TCP connections may be created — one per image, CSS file, font, JavaScript bundle. Each connection gets its own row in the NAT table. For an office with 200 employees each with a browser open, the NAT table can easily have 10,000–50,000 active entries. The router must search this table at line-rate for every packet in both directions.

This is not a trivial data structure problem. Modern NAT routers use hash tables indexed by the 5-tuple (source IP, source port, destination IP, destination port, protocol) for O(1) lookups. The table itself lives in the router's dedicated memory, separate from the routing table.

NAT/PAT Translation Table

This is a live NAT table (PAT mode). One public IP 203.0.113.5 serves all inside hosts by multiplexing via port numbers.

Inside LocalInside Global (PAT)Outside GlobalProtoStateTTL(s)
192.168.1.10:54321203.0.113.5:543218.8.8.8:53UDPActive30
192.168.1.20:49152203.0.113.5:49152172.217.0.1:443TCPEstablished86400
192.168.1.30:52000203.0.113.5:5200093.184.216.34:80TCPSYN_SENT60

Inside Local: private source IP:port. Inside Global: public IP:port (translated). Port number is preserved in PAT when possible. If port conflicts, the router assigns a new port.

NAT and Application Layer Gateways (ALGs)

PAT works cleanly for protocols where addresses are only in IP/TCP headers. But some protocols embed IP addresses in the application payload — and those embedded addresses are not translated by basic NAT:

FTP Active Mode: the client sends its IP:port in the DATA channel within the PORT command. The server tries to connect back to that private IP — which is unreachable from the internet. Fix: FTP Passive Mode (PASV) or NAT FTP ALG.

SIP (VoIP): Session Description Protocol (SDP) bodies embed IP:port for media streams. NAT breaks SIP without a SIP ALG or STUN/TURN infrastructure.

IPsec ESP: ESP encrypts the entire packet including port numbers, so NAT cannot track connections. NAT-T (UDP port 4500 encapsulation) wraps ESP in UDP to work around this.

WebRTC: uses ICE (Interactive Connectivity Establishment) with STUN/TURN to discover and traverse NAT, establishing peer-to-peer paths even behind symmetric NAT.

◆ Wow:Symmetric NAT (where each unique destination gets a different translated port) breaks STUN-based NAT traversal. WebRTC applications must fall back to TURN relay servers when both peers are behind symmetric NAT — which routes all media traffic through a TURN server rather than peer-to-peer. This is why some corporate networks with strict NAT policies cause WebRTC video calls to be significantly slower — all video traffic is relayed instead of going direct.

// Chapter 04

NAT Security Implications

"NAT gives us a free firewall" is one of the most dangerous myths in network security. A NAT router does drop inbound connections by default — there is no translation entry, so the packet is discarded. But this is a side effect of stateful connection tracking, not a security policy. The moment you add port forwarding, the "firewall" has a specific hole. And the moment a device inside the NAT initiates any outbound connection, that connection is tracked and inbound traffic on that session is welcomed.

A real firewall enforces policies based on application, user identity, threat intelligence, and content inspection. NAT enforces nothing — it just manages address translation.

NAT does provide implicit inbound filtering for unsolicited traffic — packets arriving at the public IP without an existing translation entry are dropped because there is nowhere to forward them. This incidentally blocks many opportunistic scans and unsolicited inbound connections.

But NAT provides zero protection against:

• Malware that initiates outbound connections (C2 callbacks, data exfiltration)

• Drive-by downloads and browser exploits

• DNS-based attacks and DNS exfiltration

• Any attack embedded within allowed application traffic (HTTP, HTTPS)

• IPv6 traffic (if IPv6 is deployed alongside NAT IPv4, it bypasses NAT entirely)

⚠ Warning:If IPv6 is enabled alongside NAT IPv4 (dual-stack), every device has a globally routable IPv6 address. Those IPv6 addresses are NOT behind NAT and have no equivalent "implicit inbound filtering" — unless your firewall explicitly blocks inbound IPv6 traffic. Many corporate networks deploy NAT on IPv4 but forget to apply equivalent firewall rules to IPv6, creating a wide-open attack surface on the IPv6 side.

CGNAT and Port Exhaustion

Carrier-Grade NAT (CGNAT, RFC 6888) applies a second NAT layer at the ISP level: thousands of customers share a block of public IPs in the 100.64.0.0/10 range. This solves the ISP's IPv4 exhaustion but introduces severe problems for applications:

• Port forwarding for home servers is impossible (customer gets a CGNAT IP, not a real public IP)

• Law enforcement tracing by IP becomes ambiguous (thousands of customers share one IP at any moment)

• Some gaming platforms, WebRTC, and VPN protocols fail behind double-NAT

• IP reputation systems mistakenly penalize the shared CGNAT IP for any single misbehaving customer

// Chapter 05

DHCP — Automatic Address Assignment

Before DHCP, every device on a network needed a manually assigned IP address. In 1990, a university sysadmin managing 500 workstations spent significant time just tracking IP assignments in a spreadsheet. One typo — two machines with the same IP — and a mystery network outage would follow.

RARP (Reverse ARP) attempted to solve this in the 1980s by letting diskless workstations request an IP. BOOTP improved it with more options. Then RFC 2131 (1997) defined DHCP, which added dynamic leasing, automatic expiry, and a rich options framework. Today DHCP runs on every network — from home routers to hyperscale clouds — managing billions of address assignments.

DHCP (Dynamic Host Configuration Protocol) automates the assignment of: IP address, subnet mask, default gateway, DNS servers, and hundreds of optional parameters (NTP servers, domain name, TFTP server for PXE boot, WPAD URL for proxy autoconfiguration, etc.).

DHCP is a client-server protocol running over UDP: clients use port 68, servers use port 67. The exchange is the DORA handshake: Discover → Offer → Request → Acknowledge.

// Chapter 06

The DORA Exchange — Packet by Packet

A new laptop joins a Wi-Fi network. It has no IP address, no gateway, no DNS — it knows nothing about the network except the link-layer connection. Within milliseconds of joining, it begins the DORA exchange, and within a second or two it has a fully configured IP stack. This happens billions of times per day on every network on the planet. The DORA sequence is a masterpiece of bootstrap protocol design.

DHCP DORA Exchange — Packet Inspector

Step through the 4-message DHCP lease acquisition process and inspect each packet's fields.

DHCPDISCOVERClient → Broadcast
Source IP

0.0.0.0

Destination IP

255.255.255.255

Source MAC

AA:BB:CC:DD:EE:FF

UDP Ports

68 → 67

DHCP OPTIONS / PAYLOAD

Message Type: DISCOVER
Client Hardware Address: AA:BB:CC:DD:EE:FF
Transaction ID: 0x3903F326
Parameter Request List: [Subnet Mask, Router, DNS, Domain Name]
Client has no IP. Broadcasts a DISCOVER to find any DHCP server. Source IP is 0.0.0.0 (none yet). Destination is 255.255.255.255 (entire LAN). The Transaction ID (XID) ties this exchange together.

DHCP Lease Lifecycle

DHCP leases follow a three-phase lifecycle after DORA completes:

T1 (Renewal Time): at 50% of lease duration, the client sends a unicast DHCPREQUEST directly to the server that granted the lease. If the server responds with DHCPACK, the lease is renewed with a fresh duration. Most deployments default T1 to 50% of lease time.

T2 (Rebind Time): at 87.5% of lease duration, if T1 renewal failed, the client broadcasts DHCPREQUEST to any DHCP server. This allows a different server to take over the lease if the original server is unavailable.

Expiry: if T2 also fails, the lease expires. The client must start a new DORA exchange and will likely receive a different IP address.

# Cisco IOS DHCP server configuration
! Define excluded addresses (routers, printers, servers — never auto-assign these)
ip dhcp excluded-address 192.168.1.1 192.168.1.20

! Define DHCP pool
ip dhcp pool OFFICE
  network 192.168.1.0 255.255.255.0    ! Address space
  default-router 192.168.1.1           ! Option 3: gateway
  dns-server 8.8.8.8 8.8.4.4          ! Option 6: DNS
  domain-name corp.example.com        ! Option 15: domain
  lease 1                              ! Lease duration: 1 day (86400s)
  netbios-node-type h-node             ! Option 46: WINS type (Windows)

! Static DHCP binding (always give this MAC the same IP)
ip dhcp pool PRINTER-FLOOR2
  host 192.168.1.50 255.255.255.0
  hardware-address 00:1A:2B:3C:4D:5E
  default-router 192.168.1.1

! Verify
show ip dhcp binding                   ! All active leases (IP, MAC, expiry)
show ip dhcp pool                      ! Pool utilization stats
show ip dhcp conflict                  ! IPs that caused conflicts (duplicate detection)
debug ip dhcp server events            ! Live DORA trace

// Chapter 07

DHCP Relay — Crossing Layer 3 Boundaries

DHCP Discover is a broadcast. It reaches every device on the local subnet, but it does not cross a router. A large enterprise with 50 VLANs would need 50 separate DHCP servers — one per subnet — if broadcasts were the only mechanism. That is obviously impractical. The solution is the DHCP relay agent (RFC 3046): a router or Layer 3 switch that intercepts DHCP broadcasts and forwards them as unicasts to a central DHCP server.

The DHCP relay agent (also called IP Helper) receives the broadcast DISCOVER on the client's VLAN interface, records the incoming interface IP (the subnet gateway) as the giaddr (gateway IP address) field in the DHCP packet, and forwards it as a unicast UDP packet to the configured DHCP server. The server uses giaddr to determine which pool to allocate from. The server's reply is unicast back to the relay agent, which forwards it to the client.

! Configure DHCP relay on the VLAN interface
interface Vlan10
  ip address 10.10.0.1 255.255.0.0
  ip helper-address 192.168.1.100     ! Forward DHCP broadcasts to this server
  ip helper-address 192.168.1.101     ! Second DHCP server for redundancy

! ip helper-address forwards 8 UDP services by default:
!   TFTP (69), DNS (53), DHCP/BOOTP (67/68), TACACS (49),
!   NetBIOS Name Service (137/138), IEN-116 Name Service (42), Time (37)
! To restrict to DHCP only:
no ip forward-protocol udp 69        ! Disable TFTP forwarding
no ip forward-protocol udp 137       ! Disable NetBIOS forwarding

! Verify relay operation
debug ip dhcp server packet           ! See DISCOVER arriving from relay (giaddr set)
⚠ Warning:If you configure ip helper-address but DHCP clients still get no IP, check: (1) the DHCP server has a pool matching the giaddr subnet, (2) the server can route replies back to the relay agent's IP (the gateway interface), and (3) no ACL on the router is blocking UDP 67/68. A common mistake is forgetting to add the DHCP subnet to the excluded-address list on the server, causing the server to offer the gateway's own IP to clients.

// Chapter 08

DHCPv6 and SLAAC — Address Assignment in IPv6

IPv6 was designed partly to eliminate the need for NAT by giving every device a globally unique address. It also designed address assignment to be simpler than DHCPv4 — specifically, to allow devices to configure themselves without any server at all using SLAAC (Stateless Address Autoconfiguration). But then enterprises needed features like DNS provisioning and prefix delegation, so DHCPv6 was created. And then we discovered that some environments need SLAAC for address assignment and DHCPv6 just for options. So now IPv6 has three address assignment methods and two flags to control which ones are used.

Welcome to the glorious complexity of IPv6 address management.

IPv6 address assignment uses three mechanisms, controlled by flags in Router Advertisements (RA):

SLAAC (Stateless Address Autoconfiguration): the client uses the router's advertised prefix + its own interface identifier (EUI-64 or random) to construct an address. No server needed. The RA M-flag = 0 and O-flag = 0 indicates pure SLAAC.

Stateless DHCPv6: SLAAC for address + DHCPv6 for options (DNS servers, domain name). RA has M-flag = 0, O-flag = 1. The client autoconfigures its address from the prefix but queries a DHCPv6 server for configuration options only.

Stateful DHCPv6: DHCPv6 assigns both address and options, like DHCPv4. RA has M-flag = 1. Server maintains a binding database. Required for environments that need to control exactly which address each client gets.

! IPv6 Router Advertisement configuration (IOS)
interface GigabitEthernet0/0
  ipv6 address 2001:db8:1::1/64
  ipv6 nd managed-config-flag         ! M-flag = 1: use stateful DHCPv6 for address
  ipv6 nd other-config-flag           ! O-flag = 1: use DHCPv6 for options

! Stateful DHCPv6 pool
ipv6 dhcp pool OFFICE-V6
  address prefix 2001:db8:1::/64 lifetime 86400 3600
  dns-server 2001:4860:4860::8888
  domain-name corp.example.com

interface GigabitEthernet0/0
  ipv6 dhcp server OFFICE-V6

! DHCPv6 relay (like ip helper-address for IPv6)
interface Vlan20
  ipv6 address 2001:db8:2::1/64
  ipv6 dhcp relay destination 2001:db8:255::100 GigabitEthernet0/1

! Verify
show ipv6 dhcp binding                ! Active DHCPv6 leases
show ipv6 neighbors                   ! NDP neighbor table (IPv6 ARP equivalent)
◆ Wow:SLAAC's EUI-64 address generation creates a privacy problem: it embeds the device's MAC address in the IPv6 address, making it trackable across networks. RFC 4941 (Privacy Extensions for SLAAC) addresses this by generating a random 64-bit interface ID that changes periodically. Modern operating systems (Windows, macOS, Linux) use RFC 4941 by default, generating temporary addresses for outbound connections while keeping a stable "stable privacy" address for inbound services.

// Chapter 09

DHCP Security — Starvation, Spoofing, and Snooping

An attacker on a shared Ethernet segment runs a tool that sends thousands of DHCPDISCOVER messages with spoofed MAC addresses. The legitimate DHCP server exhausts its address pool responding to fake requests. Within seconds, new clients on the segment cannot get an IP address — a DHCP starvation attack.

Then the attacker sets up a rogue DHCP server that hands out addresses with the attacker's machine as the default gateway — a DHCP spoofing attack. New clients configure themselves with the rogue gateway and all their traffic flows through the attacker. This is a man-in-the-middle attack achieved entirely through DHCP.

Neither attack requires any hacking skill — they require only a laptop, a free tool, and access to a switch port.

DHCP attacks are among the most accessible Layer 2 attacks. The defenses are built into modern switches:

DHCP Snooping (IEEE 802.1Q): the switch differentiates between trusted ports (connecting to DHCP servers) and untrusted ports (connecting to clients). DHCP OFFER and DHCPACK messages on untrusted ports are dropped. The switch also builds a DHCP snooping binding table (IP-to-MAC-to-port mappings) that feeds Dynamic ARP Inspection and IP Source Guard.

! Enable DHCP snooping (Cisco IOS-based switch)
ip dhcp snooping                           ! Enable globally
ip dhcp snooping vlan 10,20,30             ! Enable on specific VLANs

! Mark the uplink to DHCP server as trusted
interface GigabitEthernet0/24
  ip dhcp snooping trust                   ! Allow DHCP server responses

! Rate-limit client-facing ports (starvation defense)
interface GigabitEthernet0/1
  ip dhcp snooping limit rate 15           ! Max 15 DHCP packets/second

! Verify
show ip dhcp snooping binding              ! Binding table (IP, MAC, VLAN, port)
show ip dhcp snooping statistics           ! Dropped messages by reason

! Dynamic ARP Inspection (builds on snooping table)
ip arp inspection vlan 10,20,30
interface GigabitEthernet0/24
  ip arp inspection trust                  ! Only trust ARP from this uplink
⚠ Warning:DHCP snooping inserts a DHCP option 82 (relay agent information) tag into packets forwarded by the switch. If the DHCP server is not configured to accept option 82 or strips it, clients may not receive responses. This is a common "DHCP snooping breaks DHCP" failure — check ip dhcp snooping information option and the server's option 82 handling configuration.

// Chapter 10

NAT and Firewall Interaction

A company deploys a stateful firewall between the internet and the internal network. The firewall also does PAT. A security engineer wants to know: does NAT happen before or after firewall policy inspection? Does the firewall see the private IP or the public IP when evaluating rules?

The answer depends entirely on the vendor and configuration. In Cisco ASA, NAT happens after firewall policy (policies reference pre-NAT addresses). In iptables/nftables, the order is controlled by the chain order (PREROUTING DNAT happens before FORWARD chain filtering). In Palo Alto, the firewall inspects using pre-NAT source and post-NAT destination by default. Getting this wrong means writing firewall rules that never match — a silent security failure.

Modern next-generation firewalls (NGFW) integrate NAT and firewall policy in a unified platform. Key behaviors to understand:

Cisco ASA: NAT rules are evaluated after access-list inspection. Firewall policy uses pre-NAT (real) addresses. Object NAT is evaluated before twice-NAT.

Palo Alto Networks: Security policy uses pre-NAT source and post-NAT destination for matching. NAT rules run in a separate evaluation pass.

iptables (Linux): DNAT (destination NAT, port forwarding) happens in PREROUTING before the FORWARD chain. SNAT happens in POSTROUTING after the FORWARD chain. Rules in FORWARD see post-DNAT destination but pre-SNAT source.

# Linux iptables NAT + firewall
# PREROUTING: port forward before firewall evaluation
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.100:443

# FORWARD: firewall rules see post-DNAT destination (192.168.1.100)
iptables -A FORWARD -d 192.168.1.100 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT

# POSTROUTING: PAT for all outbound traffic
iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -o eth0 -j MASQUERADE

# nftables equivalent (modern Linux)
table ip nat {
    chain prerouting {
        type nat hook prerouting priority dstnat;
        iif eth0 tcp dport 443 dnat to 192.168.1.100:443
    }
    chain postrouting {
        type nat hook postrouting priority srcnat;
        oif eth0 masquerade
    }
}

// Chapter 11

DHCP Options Deep Dive

DHCP is not just about IP addresses. It is a general-purpose configuration distribution mechanism. A client can request dozens of parameters from the server, and the server can push options the client didn't even ask for. Enterprises use DHCP options to automate VoIP phone provisioning, push WPAD proxy URLs to browsers, direct PXE clients to the right TFTP server, and configure NTP servers — all without touching a single endpoint manually.

DHCP options use the TLV (Type-Length-Value) format defined in RFC 2132. Key options in production environments:

DHCP Option Reference (RFC 2132 + extensions)
--
Option 1:   Subnet Mask           (e.g., 255.255.255.0)
Option 3:   Router / Default GW   (e.g., 192.168.1.1)
Option 6:   DNS Servers           (e.g., 8.8.8.8 8.8.4.4)
Option 12:  Hostname              (client sends its hostname)
Option 15:  Domain Name           (e.g., corp.example.com)
Option 42:  NTP Servers           (e.g., 192.168.1.5)
Option 43:  Vendor-Specific Info  (VoIP phones, APs, PDAs)
Option 51:  IP Address Lease Time (seconds)
Option 52:  Option Overload       (extends into sname/file fields)
Option 53:  DHCP Message Type     (DISCOVER/OFFER/REQUEST/ACK/etc.)
Option 54:  Server Identifier     (server's IP)
Option 55:  Parameter Request List (client's wish list)
Option 58:  Renewal Time T1       (default 50% of lease)
Option 59:  Rebind Time T2        (default 87.5% of lease)
Option 60:  Vendor Class ID       (client announces device type)
Option 66:  TFTP Server Name      (for PXE boot)
Option 67:  Bootfile Name         (for PXE boot)
Option 82:  Relay Agent Info      (switch port, circuit ID — anti-spoofing)
Option 121: Classless Static Routes (RFC 3442 — push specific routes)
Option 252: WPAD URL              (Web Proxy Auto-Discovery)

Option 121 (Classless Static Routes) is particularly powerful — it lets DHCP push specific routing entries to clients. This can override the default gateway for specific prefixes, but it also creates a security risk: a rogue DHCP server injecting Option 121 with a route for 0.0.0.0/0 via an attacker-controlled gateway can completely redirect a client's traffic — including VPN traffic on some operating systems (the VPN bypass vulnerability documented in 2024).

// Chapter 12

Troubleshooting NAT and DHCP

A help desk ticket: "I can't reach the internet from my laptop." The engineer checks: the laptop has a 169.254.x.x address — APIPA self-assigned, which means DHCP failed. The DHCP server is up. The relay agent is configured. A packet capture on the server shows DISCOVER packets arriving, but no OFFER going out. The reason: the server's address pool was exhausted — 800 leases with a 7-day lease time, and the building had been hosting a conference for a week. Every visitor's device took a lease and left, but the leases hadn't expired yet. Fix: reduce lease time to 4 hours for the conference VLAN, or clear expired leases manually.

DHCP Troubleshooting Commands

! Client side (Windows)
ipconfig /all                          ! Show current DHCP lease, server IP, lease times
ipconfig /release                      ! Release the current lease
ipconfig /renew                        ! Perform new DORA exchange
netsh dhcp client show all

! Client side (Linux)
dhclient -v eth0                       ! Verbose DHCP client, shows DORA exchange
journalctl -u NetworkManager | grep DHCP

! Server side (IOS)
show ip dhcp binding                   ! Lease table — check utilization
show ip dhcp pool POOLNAME             ! Free vs. allocated addresses
show ip dhcp conflict                  ! IPs that triggered duplicate detection
clear ip dhcp binding *                ! Clear all leases (emergency fix for exhaustion)

! Relay debugging
debug ip dhcp server packet            ! Verify DISCOVER arrives with correct giaddr
show ip helper-address                 ! Check relay config

NAT Troubleshooting Commands

! Verify translation is happening
show ip nat translations               ! Active entries in NAT table
show ip nat translations verbose       ! With timeout remaining

! Statistics
show ip nat statistics                 ! Hits, misses, expired translations, pool usage

! Clear specific or all translations
clear ip nat translation *             ! Nuclear option — drops all active sessions

! Debug (use carefully — very verbose)
debug ip nat                           ! Live NAT event log
debug ip nat detailed                  ! Per-packet NAT decisions

! Check NAT is configured correctly
show running-config | include nat       ! Verify nat inside/outside and ip nat statements

A common NAT issue is asymmetric routing: packets go out via the NAT router but return via a different path. The NAT router never sees the return traffic, so it never creates the reverse translation entry. The fix: ensure symmetric routing so both directions of a flow traverse the same NAT device, or use stateful NAT clusters with session synchronization.

// Chapter 13

Common Misconceptions

✗ Misconception:NAT is a security feature that protects the internal network. NAT provides incidental inbound filtering as a side effect of stateful connection tracking. It is not a security mechanism. A properly configured stateful firewall with explicit deny-all default is required for actual security. NAT does nothing to stop outbound malware, exfiltration, or drive-by downloads. Relying on NAT as a security control creates false confidence and leaves real attack vectors unaddressed.
✗ Misconception:DHCP leases are permanent once assigned. DHCP leases expire. A device that is off the network for longer than the lease duration will return to find its IP reassigned to another device. The new DORA exchange will give it a different IP. Applications that hard-code the DHCP-assigned IP will break. Use DHCP reservations (static bindings by MAC) for servers and infrastructure, or use static IP assignment. DHCP is designed for dynamic hosts.
✗ Misconception:Two devices with the same IP on the same subnet can coexist without issues. Duplicate IP addresses cause intermittent connectivity for both devices and are extremely difficult to diagnose. ARP replies from both devices compete — whichever replied most recently wins in the neighbor's ARP cache, causing traffic to randomly route to one machine or the other. Use DHCP to prevent manual assignment conflicts, enable DAD (Duplicate Address Detection) for IPv6, and monitor DHCP conflict logs for early warning.
✗ Misconception:DHCPv6 replaces SLAAC in IPv6. DHCPv6 and SLAAC coexist and serve different purposes. SLAAC uses Router Advertisement prefixes for address autoconfiguration; DHCPv6 provides options (DNS, domain). The M and O flags in RAs determine which mechanisms clients use. Many mobile devices and modern OSes prefer SLAAC + RDNSS (DNS option in RA, RFC 8106) over DHCPv6. Android famously ignored DHCPv6 for many years, relying entirely on SLAAC+RDNSS. In mixed environments, configure both mechanisms and verify with actual client behavior.
✗ Misconception:DHCP snooping can be safely enabled without impact. Enabling DHCP snooping has several potential impacts: it drops DHCP OFFERs from untrusted ports (correct), inserts Option 82 into relayed packets (may break some servers), and can cause ACK delays if the binding table lookup is slow on high-traffic switches. Before enabling on production, audit all uplink ports are marked trusted and verify the DHCP server handles or ignores Option 82. Test in a maintenance window or lab first.
✗ Misconception:NAT64 allows IPv6 clients to reach all IPv4 services transparently. NAT64 requires DNS64 to synthesize AAAA records from A records, allowing IPv6 clients to resolve IPv4-only hostnames. However, it does not work for applications that embed raw IPv4 addresses in application data (bypassing DNS), applications using DNSSEC (DNS64 synthesized records cannot be validated), or some applications that use IP literal addresses in their protocols. NAT64 + DNS64 covers most HTTP/S traffic but requires careful testing for legacy applications.

// Chapter 14

Depth Check

BEGINNERWhat is the difference between NAT and PAT? NAT (Network Address Translation) rewrites IP addresses in packet headers. PAT (Port Address Translation), also called NAT Overload, additionally rewrites port numbers — allowing many inside devices to share a single public IP by differentiating flows via port numbers. PAT is the dominant form in home/office routers (one public IP, many devices).
BEGINNERWhat is the DORA sequence and what does each message do? DISCOVER: client broadcasts to find a server. OFFER: server proposes an IP address and configuration. REQUEST: client broadcasts acceptance of a specific offer (and implicitly rejects others). ACK: server confirms the lease. All four messages use UDP with source port 68 (client) and destination port 67 (server).
INTERMEDIATEWhy does DHCPREQUEST use broadcast even after the server already offered a unicast IP? The client must inform ALL DHCP servers which offer it accepted. If it unicasted only to the selected server, other servers would not know their offers were rejected and would hold their offered IP addresses in limbo indefinitely. The broadcast ensures all servers see the REQUEST, allowing un-selected servers to release their offered IPs back to their pools.
SENIORExplain how NAT affects TCP connection tracking and what happens during NAT table exhaustion. NAT maintains a 5-tuple entry (src_ip, src_port, dst_ip, dst_port, protocol) for each active flow. TCP states (SYN_SENT, ESTABLISHED, FIN_WAIT, TIME_WAIT) determine entry timeout — established TCP entries may persist 24 hours. Under exhaustion, the router cannot create new translation entries — new connection attempts are silently dropped. Recovery requires either clearing stale entries, reducing timeouts, adding public IPs to the NAT pool, or load-balancing across multiple NAT routers. Monitoring NAT table utilization is critical for capacity planning.
SENIORWhat is the DHCP Option 121 VPN bypass vulnerability and how does it work? RFC 3442 Option 121 allows DHCP to push classless static routes to clients. A rogue DHCP server (or one controlled by an attacker on a network) can push a route for the VPN server's IP via the attacker's gateway — before the VPN tunnel is established. Some VPN clients (particularly split-tunnel configurations) honor these routes and send pre-tunnel traffic to the VPN server via the rogue gateway, allowing the attacker to intercept credentials. Mitigation: use full-tunnel VPN (all traffic inside tunnel), use network-based firewall policies, and configure OS-level DHCP option 121 ignore settings where supported.
PHDHow does NAT interact with TCP sequence number randomization and what are the implications for connection reuse attacks? NAT routers that perform TCP sequence number randomization (ISN randomization) rewrite sequence numbers in addition to addresses and ports. This prevents blind TCP injection attacks that exploit predictable ISNs. However, this introduces state: the NAT router must track the ISN offset for each connection to translate sequence numbers in both directions. If the NAT entry is cleared (timeout or failure) and the TCP session is reused (same 5-tuple), the router sees incorrect sequence numbers and drops packets with RST. This is why NAT timeouts must be longer than typical TCP TIME_WAIT (120s default, 2 × MSL). In high-connection-rate environments (load balancers, API gateways), ISN translation adds measurable CPU overhead — some production NAT implementations disable it, accepting the security trade-off in exchange for performance at scale.

🎯 Key Takeaways

  • NAT stretches IPv4 by rewriting packet headers at private/public boundaries. PAT multiplexes thousands of private hosts through a single public IP using port number differentiation.
  • The NAT translation table maps (inside_ip, inside_port, protocol) → (outside_ip, outside_port). Table exhaustion silently drops new connections — monitor utilization proactively.
  • NAT is NOT a security feature. It provides incidental inbound filtering as a side effect of connection tracking, but provides zero protection against outbound malware, exfiltration, or application-layer attacks.
  • DHCP DORA sequence: DISCOVER (0.0.0.0 → 255.255.255.255) → OFFER (server → broadcast) → REQUEST (0.0.0.0 → broadcast, announces selected server) → ACK (server confirms lease).
  • DHCPREQUEST is broadcast — not unicast — so all DHCP servers learn which offer was accepted and can release their offers back to their pools.
  • DHCP relay agents (ip helper-address) forward broadcast DISCOVER as unicast to a central server, stamping the giaddr field with the relay interface IP so the server knows which pool to allocate from.
  • DHCP snooping protects against rogue DHCP servers by classifying switch ports as trusted (uplinks to real servers) or untrusted (client ports). OFFER/ACK from untrusted ports are dropped.
  • IPv6 uses SLAAC (prefix + EUI-64/random interface ID), stateless DHCPv6 (SLAAC address + DHCPv6 options), or stateful DHCPv6 (DHCPv6 assigns everything). M and O flags in Router Advertisements select the mode.
  • DHCP Option 121 (classless static routes) can be weaponized by rogue DHCP servers to redirect traffic before VPN tunnels establish — a real attack vector requiring full-tunnel VPN or OS-level mitigation.
  • Duplicate IP addresses cause random connectivity failures for both conflicting devices. Prevent with DHCP for dynamic hosts, static reservations for infrastructure, and DHCP conflict monitoring.
Share

Discussion

0

Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.

Continue with GitHub
Loading...