Computer Network 📂 Network Layer · 6 of 6 59 min read

NAT & DHCP Explained: How Your Network Gets Addresses and Shares the Internet

Discover how DHCP automatically assigns IP addresses using the DORA sequence (Discover, Offer, Request, Acknowledge), and how NAT/PAT lets thousands of private devices share a single public IP. Features fully animated DORA flow, PAT translation table, relay agent diagram, lease lifecycle, and a complete phone-to-internet end-to-end walkthrough. Includes real incidents and Cisco IOS configs.

Section 01

The Problem — Why NAT and DHCP Exist

An Office Block with One Street Address
Imagine a 500-person office building. The building has one street address visible to the outside world. Inside, every desk has its own internal room number — but couriers only know the building's single address.

When post arrives addressed to the building, the reception desk (NAT) reads which internal room it's meant for and routes it accordingly. When a new employee joins, they don't bring their own room number from home — the facilities manager (DHCP) automatically assigns them one from a pool, along with the building's phone directory and post room address.

That is exactly what NAT and DHCP do for networks — and without them, the IPv4 internet would have run out of addresses in the 1990s.
🌍
The IPv4 Crisis
Only 4.29 billion addresses
IPv4 allows ~4.29 billion unique addresses. With 15+ billion connected devices worldwide, every device cannot have a public IP. NAT lets thousands of devices share one.
🔌
Manual Configuration Hell
Before DHCP: 1984–1993
Before DHCP, every device needed a manually configured IP address, subnet mask, gateway, and DNS server. In a 500-device office, this was a full-time job — and errors were constant.
The Modern Solution
NAT + DHCP together
DHCP automatically hands out private IP addresses from RFC 1918 space. NAT translates those private IPs to a shared public IP at the router edge. Together they are invisible infrastructure.
📌
RFC 1918 — Private IP Address Ranges

Three blocks are reserved for private use — they are never routed on the public Internet:
10.0.0.0 / 8 — ~16.7 million addresses (large enterprises)
172.16.0.0 – 172.31.255.255 / 12 — ~1 million addresses (medium networks)
192.168.0.0 / 16 — ~65,000 addresses (home & small office — most common)
DHCP gives out addresses from these ranges. NAT translates them to your single public IP.


Section 02

DHCP — Dynamic Host Configuration Protocol

DHCP (RFC 2131, 1997) automatically assigns network configuration to devices the moment they connect. A device does not need any prior configuration — it simply broadcasts "I need an address!" and the DHCP server responds with everything needed: IP address, subnet mask, default gateway, DNS servers, and a lease duration.

📥 What DHCP Assigns to Each Client
IP Address
A unique private IP from the configured pool, e.g. 192.168.1.45
Subnet Mask
Defines the network boundary, e.g. 255.255.255.0 (/24)
Default Gateway
The router's IP — where packets go when the destination is outside the local subnet, e.g. 192.168.1.1
DNS Servers
Where to resolve domain names, e.g. 8.8.8.8, 8.8.4.4
Lease Time
How long the address is valid before it must be renewed, e.g. 86400 seconds (24 hours)
Optional
Domain name, NTP servers, TFTP server (for VoIP phones & PXE boot), WINS servers

Section 03

🏭 Animated: The DHCP DORA Process — Full Working

DHCP works in four messages remembered as DORA: Discover → Offer → Request → Acknowledge. Every device joining a network goes through this exact sequence. The entire exchange completes in milliseconds.

▶ DHCP DORA Animation — Complete IP Assignment Sequence
Click Play or Step to begin

💡 DHCP Discover and Request use broadcast (255.255.255.255) because the client has no IP yet. Offer and Acknowledge are sent to the client's MAC address (unicast or broadcast depending on implementation).


Section 04

DHCP Lease Lifecycle — Renewal, Rebinding & Expiry

A DHCP lease is not permanent. The server sets a lease time and the client must renew before it expires. This allows addresses to be reclaimed from devices that have left the network (like a phone that disconnected weeks ago).

📊 DHCP Lease Timer States

T1 = 50% of lease time (unicast renewal attempt). T2 = 87.5% of lease time (broadcast rebind to ANY server). Expiry = address released back to pool.

📌
DHCPRELEASE
Graceful surrender
When a device disconnects gracefully (e.g., shutdown), it sends DHCPRELEASE to the server. The server immediately marks the address as available. Not all OSes send this — Windows does, some embedded devices don't.
🚫
DHCPNAK
Negative Acknowledge
The server sends DHCPNAK when it cannot honour a renewal request — e.g., the client moved to a different subnet or the address was reassigned. The client must restart the DORA process from scratch.
🔍
DHCPDECLINE
Address conflict detected
After receiving a DHCP ACK, the client ARPs to check if the offered address is already in use (RFC 2131 §2.2). If another device responds, the client sends DHCPDECLINE and restarts. Prevents IP conflicts.

DHCP Relay — Crossing Router Boundaries

DHCP uses broadcasts — and routers do not forward broadcasts between subnets. How does a device on a remote subnet reach the DHCP server? A DHCP Relay Agent (also called IP Helper) solves this.

🔄 DHCP Relay Agent — One Server, Many Subnets

The relay agent intercepts the broadcast Discover on the local subnet and forwards it as a unicast packet to the DHCP server — inserting the client's subnet information (giaddr) so the server knows which pool to assign from.

💡
Cisco IOS — DHCP Server & Relay Configuration

Configuring a Cisco router as both DHCP server and relay agent requires only a handful of commands. The ip helper-address command on the client-facing interface is the key for relay.

! ── Cisco IOS: Configure router as DHCP SERVER ──────────────
Router(config)# ip dhcp excluded-address 192.168.1.1 192.168.1.49  ! Reserve for statics
Router(config)# ip dhcp pool OFFICE_LAN
Router(dhcp-config)#  network      192.168.1.0 255.255.255.0
Router(dhcp-config)#  default-router 192.168.1.1
Router(dhcp-config)#  dns-server   8.8.8.8 8.8.4.4
Router(dhcp-config)#  lease        1             ! 1 day
Router(dhcp-config)#  domain-name  office.local

! ── DHCP RELAY on a router interface facing clients ──────────
Router(config)# interface GigabitEthernet0/1
Router(config-if)# ip helper-address 10.0.1.100  ! Forward broadcasts to DHCP server

! ── Verify leases ────────────────────────────────────────────
Router# show ip dhcp binding
Router# show ip dhcp pool
Router# show ip dhcp conflict
DHCP BINDING TABLE
IP address Client-ID/Hardware Addr Lease expiration Type 192.168.1.50 AA:BB:CC:DD:EE:01 Jul 04 2026 08:12 AM Automatic 192.168.1.51 AA:BB:CC:DD:EE:02 Jul 04 2026 09:45 AM Automatic 192.168.1.52 AA:BB:CC:DD:EE:03 Jul 04 2026 11:30 AM Automatic

Section 05

DHCP Security — Starvation, Spoofing & Snooping

🚫
DHCP Starvation Attack
An attacker floods the DHCP server with Discover messages using thousands of spoofed MAC addresses, exhausting the entire address pool. Legitimate clients get no IP address. Tools like Gobbler can do this in seconds. Mitigated by DHCP Snooping + port rate limiting.
Attack: Pool exhaustion | Fix: Snooping
Rogue DHCP Server
An attacker connects an unauthorised DHCP server to the network. It races the legitimate server to respond with offers — assigning itself as the gateway. All client traffic now flows through the attacker (MITM). Mitigated by marking switch ports as trusted or untrusted in DHCP Snooping.
Attack: MITM gateway hijack | Fix: Snooping
🔐
DHCP Snooping (Defence)
A switch feature that classifies ports as trusted (uplinks to DHCP servers) or untrusted (client ports). Untrusted ports cannot send DHCP Offer or ACK messages — only Discover and Request. Builds a binding table (IP↔MAC↔port) used by Dynamic ARP Inspection (DAI).
Defence: Switch-level enforcement
📰
Real Incident: Rogue DHCP Servers at University Networks

In 2019, a student at a UK university accidentally connected a consumer router to the campus network with DHCP enabled. The rogue router began assigning itself as the default gateway to hundreds of devices, causing intermittent Internet outages for an entire building for 6 hours. Rogue DHCP incidents are among the most common self-inflicted network outages in large organisations. Source: JANET UK Network Security Notes, 2019; Cisco CCNA Security guide.


Section 06

NAT — Network Address Translation

NAT (RFC 3022) allows an entire private network to share one (or a few) public IP addresses. A NAT device — typically your router — maintains a translation table mapping each private IP:port pair to a unique public IP:port pair. Outbound packets get their source rewritten; inbound replies get their destination rewritten back.

Without NAT, every device in your home or office would need its own globally unique public IP address. With ~4.29 billion IPv4 addresses and 15+ billion connected devices, this is mathematically impossible. NAT is what kept the IPv4 internet alive after 1994.

Outbound Translation
{privIP:privPort} → {pubIP:pubPort}
Router replaces source IP and port with its own public IP and a unique tracking port. Adds entry to NAT table.
Inbound Translation
{pubIP:pubPort} → {privIP:privPort}
Router receives reply to pubIP:pubPort, looks up the NAT table, replaces destination with the original private IP:port, and delivers to the correct internal host.

Three Types of NAT

👥
Static NAT
1 private IP ↔ 1 public IP
A permanent one-to-one mapping. Used for servers that must be reachable from the Internet with a fixed public address (e.g., a web server at 203.0.113.10 always maps to internal 192.168.1.100). Consumes one public IP per host.
✓ Inbound connections work
✗ Uses 1 public IP per device
🔄
Dynamic NAT
Pool of public IPs shared
Multiple private IPs map to a pool of public IPs on demand. When the pool is exhausted, new connections are blocked. More efficient than static NAT but still requires near-parity of public IPs. Rarely used in home/SME settings.
✓ Flexible allocation
✗ Still needs many public IPs
🌐
PAT / NAT Overload
Many private → ONE public IP
Port Address Translation — the most common form. Many devices share one public IP, differentiated by unique source port numbers. Your home router uses PAT. A single public IP can serve 65,535 simultaneous connections.
✓ Massively efficient
✗ No unsolicited inbound

Section 07

🏭 Animated: PAT (NAT Overload) — Full Working

PAT is what runs in your home router right now. Three devices simultaneously browsing the web — all sharing one public IP, differentiated only by their port numbers. The animation shows the complete outbound and inbound flow with the NAT table.

▶ PAT / NAT Overload — 3 Devices, 1 Public IP
Ready

💡 The NAT table is keyed by (Protocol, Private IP, Private Port). The router picks a unique ephemeral public port for each session. When the reply arrives, the router reverse-looks up the table and delivers to the correct private host.


Section 08

Port Forwarding & NAT Traversal

PAT's biggest limitation: the Internet cannot initiate a connection to a device behind NAT. The NAT table only has entries for outbound connections. Unsolicited inbound packets — like someone trying to connect to your home game server — have no matching NAT entry and are dropped. Two solutions exist: Port Forwarding (static) and NAT Traversal / STUN (dynamic).

📌 Port Forwarding — Static Inbound Rule
RuleValue
External port25565 (Minecraft)
Internal IP192.168.1.100
Internal port25565
ProtocolTCP
EffectAny inbound connection to 203.0.113.1:25565 is forwarded to 192.168.1.100:25565
🔌 STUN / ICE — Dynamic Traversal (WebRTC, VoIP)
StepAction
1Client contacts STUN server on public Internet
2STUN reflects client's public IP:port back
3Client shares its public address with peer
4Peer connects directly — NAT entry exists (hole punched)
📸
How Zoom, Teams, and WhatsApp Work Behind NAT

Every video call you make from home uses STUN (Session Traversal Utilities for NAT) and ICE (Interactive Connectivity Establishment) to punch through NAT and establish peer-to-peer connections. When direct punch-through fails (symmetric NAT), traffic falls back to a TURN relay server. This is why corporate firewalls blocking STUN/TURN ports break video calling entirely.

NAT on Cisco IOS — PAT Configuration

! ── Cisco IOS: Configure PAT (NAT Overload) ─────────────────
! Define which addresses are "inside" (private)
Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255

! Mark interfaces as inside/outside
Router(config)# interface GigabitEthernet0/0   ! LAN-facing
Router(config-if)# ip nat inside
Router(config)# interface GigabitEthernet0/1   ! WAN-facing
Router(config-if)# ip nat outside

! Enable PAT using the outside interface IP
Router(config)# ip nat inside source list 1 interface GigabitEthernet0/1 overload

! Static NAT entry (port forward) — expose internal web server
Router(config)# ip nat inside source static tcp 192.168.1.100 80 203.0.113.1 80

! Verify
Router# show ip nat translations
Router# show ip nat statistics
NAT TRANSLATION TABLE (show ip nat translations)
Pro Inside global Inside local Outside local Outside global tcp 203.0.113.1:50100 192.168.1.10:4400 142.250.80.46:443 142.250.80.46:443 tcp 203.0.113.1:50101 192.168.1.20:5500 31.13.92.36:80 31.13.92.36:80 tcp 203.0.113.1:50102 192.168.1.30:6600 13.225.0.1:443 13.225.0.1:443 tcp 203.0.113.1:80 192.168.1.100:80 --- --- (static)

Section 09

🏭 Animated: NAT + DHCP Together — New Device to Internet

This animation shows the complete journey of a new phone connecting to your home Wi-Fi and loading a webpage — combining DHCP address assignment and PAT translation in a single end-to-end flow.

▶ Full Flow — DHCP + NAT: Phone Boots → Gets IP → Browses Web
Ready

💡 The router serves dual roles here: it is both the DHCP server (assigning the phone's 192.168.1.x address) and the NAT gateway (translating that private IP to the public IP when the phone visits a website).


Section 10

Real-World Incidents & Comparison

🔥
2019 — Sprint/T-Mobile DHCP Outage
A DHCP server misconfiguration during T-Mobile's merger integration caused millions of mobile subscribers to lose data connectivity for several hours. Devices could associate with cell towers but received no IP address — making calls possible but data dead. Highlighted DHCP as critical single-point-of-failure infrastructure. Source: The Verge, April 2019.
Protocol: DHCP | Impact: Millions of users
🌐
2011 — IANA Last IPv4 Block Allocated
On 3 February 2011, IANA allocated the last five /8 blocks of IPv4 addresses to regional registries. This was the moment NAT's importance became undeniable. Without NAT enabling address sharing, the Internet would have run out of publicly routable addresses a decade earlier. Source: IANA, BBC News Feb 2011.
Protocol: NAT | Context: IPv4 exhaustion
2020 — BGP Leak + NAT Cascade Failure
A major BGP route leak caused traffic to be rerouted through an undersized ISP. The resulting congestion caused NAT table overflow on thousands of home routers — TCP state tables filled up, causing new connections to be silently dropped while old sessions appeared healthy. Source: Cloudflare Blog, 2020.
Protocol: NAT state table | NAT table overflow

NAT vs DHCP — Side-by-Side

FeatureDHCPNAT / PAT
PurposeAssign IP addresses automaticallyShare one public IP across many private IPs
OSI LayerApplication (Layer 7) over UDPNetwork (Layer 3) — IP header rewriting
Port numbersClient: 68, Server: 67Tracks sessions via port numbers (PAT)
RFCRFC 2131 (1997)RFC 3022 (2001)
Where it runsServer (router, Windows Server, ISC DHCP)Edge router / firewall
IPv6 equivalentDHCPv6 or SLAAC (stateless)NAT64 / not needed with enough IPv6 space
Security riskRogue DHCP / starvationNAT table overflow / application breakage
Stateful?Yes — lease databaseYes — translation table (TCP state)
Breaks withNo server reachable; pool exhaustedFTP active mode; SIP; IPsec ESP (without NAT-T)
📌
Protocols That Break with NAT — and the Fixes

FTP Active Mode: The server initiates a connection back to the client — NAT blocks it. Fix: use FTP Passive Mode (client initiates both connections).
SIP / VoIP: SIP embeds the private IP in the packet payload — NAT only rewrites headers. Fix: SIP Application Layer Gateway (ALG) or STUN/ICE.
IPsec ESP: Encrypts the transport header including ports — NAT can't track sessions. Fix: NAT-Traversal (UDP encapsulation of ESP, RFC 3948).


Section 11

Golden Rules — DHCP & NAT

📌 Non-Negotiable Rules for Every Network Engineer
1
Always exclude static addresses from the DHCP pool. Routers, servers, printers, and cameras with static IPs must be excluded with ip dhcp excluded-address before configuring the pool. Failure to do so causes IP conflicts when DHCP eventually assigns that address.
2
Enable DHCP Snooping on every managed switch. Mark only uplinks to the DHCP server as trusted. All end-user ports are untrusted. This single command prevents rogue DHCP servers, starvation attacks, and is a prerequisite for Dynamic ARP Inspection (DAI).
3
Set lease times based on network churn rate. Short leases (1h) for DHCP pools serving high-turnover environments like cafés and conference halls — addresses reclaim quickly. Long leases (24–48h) for offices where devices are fixed. Very long leases waste addresses in dynamic environments.
4
Never place a NAT router between two internal subnets. NAT is for the boundary between private and public networks only. NAT between internal subnets breaks routing symmetry, causes asymmetric path issues, and makes debugging a nightmare. Use routing (OSPF/static) between internal subnets.
5
PAT state table capacity is a real limit — monitor it. A typical SOHO router NAT table holds 4,096–16,384 entries. Under load (many TCP connections, P2P software, port scanners), this fills up and new connections are silently dropped. Enterprise routers hold millions of sessions and must be sized for peak concurrent flows.
6
Disable DHCP ALG (Application Layer Gateway) unless needed. Many routers enable SIP ALG by default — it attempts to rewrite SIP packets passing through NAT. In practice it often corrupts them, breaking VoIP calls. Unless your VoIP equipment specifically requires it, disable SIP ALG and use STUN/ICE at the endpoint instead.
7
DHCP and NAT are both stateful — plan your failover. If your DHCP server crashes, clients with unexpired leases continue working — but new clients get nothing. NAT table loss (on router reboot) drops all active sessions. In high-availability designs, use DHCP server redundancy (Windows DHCP failover, ISC DHCP failover protocol) and stateful NAT HA.
🎓
The Complete Picture

DHCP is the invisible concierge that greets every device joining your network — handing it an identity (IP address), directions (default gateway), and a contact list (DNS servers) automatically in milliseconds via the DORA sequence.

NAT / PAT is the shared reception desk that lets thousands of private addresses share a single public face on the Internet — tracking every conversation by port number, translating addresses on the fly, and reversing the process for incoming replies with nanosecond precision.

Together they are why the IPv4 Internet still functions — buying time until IPv6 adoption makes address scarcity a historical footnote.

You have completed Network Layer. View all sections →