Dhcp
Chapter 11: DHCP - Complete Deep Dive
Section titled “Chapter 11: DHCP - Complete Deep Dive”DHCP automates IP address assignment. This comprehensive chapter covers everything about DHCP.
11.1 Introduction to DHCP
Section titled “11.1 Introduction to DHCP”DHCP (Dynamic Host Configuration Protocol) automatically assigns network configuration to devices.
+------------------------------------------------------------------+| DHCP Overview |+------------------------------------------------------------------+
Why DHCP?+------------------------------------------------------------------+
Manual Configuration Problems:+------------------------------------------------------------------+
1. Time-consuming for many devices2. IP conflicts possible3. Difficult to change network settings4. No centralized tracking
DHCP Solutions:+------------------------------------------------------------------+
1. Centralized management2. Automatic IP assignment3. Easy to change network settings4. Prevents IP conflicts5. Efficient use of addresses
What DHCP Provides:+------------------------------------------------------------------+
1. IP Address2. Subnet Mask3. Default Gateway (Router)4. DNS Servers (Primary and Secondary)5. Domain Name6. Lease Time7. Additional Options (NTP, WINS, etc.)
+------------------------------------------------------------------+11.2 DHCP Process (DORA)
Section titled “11.2 DHCP Process (DORA)”DHCP uses a four-step process called DORA.
+------------------------------------------------------------------+| DORA Process Deep Dive |+------------------------------------------------------------------+
DHCP Four-Way Handshake:+------------------------------------------------------------------+
Step 1: DISCOVER (Client -> Server)+------------------------------------------------------------------+
Client broadcasts: "Is there a DHCP server?"
Packet details:+------------------------------------------------------------------+| Field | Value ||----------------|--------------------------------|| Source IP | 0.0.0.0 || Source Port | 68 || Dest IP | 255.255.255.255 || Dest Port | 67 || Transaction ID | Random number || Message Type | DHCP DISCOVER |+------------------------------------------------------------------+
Step 2: OFFER (Server -> Client)+------------------------------------------------------------------+
Server responds with available IP
Packet details:+------------------------------------------------------------------+| Field | Value ||----------------|--------------------------------|| Your IP | 192.168.1.100 (offered) || Subnet Mask | 255.255.255.0 || Router | 192.168.1.1 || DNS | 8.8.8.8 || Lease Time | 86400 seconds || Message Type | DHCP OFFER |+------------------------------------------------------------------+
Step 3: REQUEST (Client -> Server)+------------------------------------------------------------------+
Client requests the offered IP
Packet details:+------------------------------------------------------------------+| Field | Value ||----------------|--------------------------------|| Requested IP | 192.168.1.100 || Message Type | DHCP REQUEST |+------------------------------------------------------------------+
Step 4: ACK (Server -> Client)+------------------------------------------------------------------+
Server confirms the lease
Packet details:+------------------------------------------------------------------+| Field | Value ||----------------|--------------------------------|| Your IP | 192.168.1.100 || Lease Time | 86400 seconds || Message Type | DHCP ACK |+------------------------------------------------------------------+
Complete Flow Diagram:+------------------------------------------------------------------+
Client Server | | |------- DHCP DISCOVER ------> | | (broadcast) | | | |<------ DHCP OFFER ----------- | | (offer IP) | | | |------- DHCP REQUEST --------> | | (request IP) | | | |<------ DHCP ACK ------------- | | (confirmation) | | | |====== CONFIGURED ========== |
DHCP Nak (Negative Acknowledgment):+------------------------------------------------------------------+
If server cannot fulfill request:+------------------------------------------------------------------+
Server -> Client: DHCP NAK+------------------------------------------------------------------+
Example: Client requested IP that server no longer has
Client then starts over with DISCOVER
+------------------------------------------------------------------+11.3 DHCP Message Types
Section titled “11.3 DHCP Message Types”+------------------------------------------------------------------+| DHCP Message Types |+------------------------------------------------------------------+
DHCP Messages:+------------------------------------------------------------------+
| Type | Value | Direction | Description ||------|-------|-------------|--------------------------------|| DHCPDISCOVER | 1 | Client->Server | Find available servers || DHCPOFFER | 2 | Server->Client | Offer available IP || DHCPREQUEST | 3 | Client->Server | Request offered IP || DHCPDECLINE | 4 | Client->Server | IP already in use || DHCPACK | 5 | Server->Client | Confirm lease || DHCPNAK | 6 | Server->Client | Request rejected || DHCPRELEASE | 7 | Client->Server | Release IP early || DHCPINFORM | 8 | Client->Server | Client has IP, need config|
DHCP Packet Format:+------------------------------------------------------------------+
+------------------------------------------------------------------+| Field | Size | Description ||-------------------|-----------|-----------------------------------|| Operation | 1 byte | 1=request, 2=reply || Hardware Type | 1 byte | 1=Ethernet || Hardware Length | 1 byte | 6 for Ethernet || Hops | 1 byte | Relay agent hops || Transaction ID | 4 bytes | Matches requests/responses || Seconds | 2 bytes | Time since request started || Flags | 2 bytes | Broadcast/unicast flags || Client IP | 4 bytes | Client IP (if known) || Your IP | 4 bytes | IP being offered || Server IP | 4 bytes | Server IP || Gateway IP | 4 bytes | Relay agent IP || Client Hardware | 16 bytes | MAC address || Server Hostname | 64 bytes | Server name || Boot Filename | 128 bytes| Boot file name || Options | Variable | DHCP options |+------------------------------------------------------------------+
DHCP Options (Common):+------------------------------------------------------------------+
| Option | Code | Description | Example ||--------|------|--------------------------------|---------------------|| Subnet Mask | 1 | Network mask | 255.255.255.0 || Router | 3 | Default gateway | 192.168.1.1 || DNS | 6 | Name servers | 8.8.8.8 || Host Name | 12 | Client hostname | client-pc || Domain Name | 15 | Domain suffix | example.com || Broadcast | 28 | Broadcast address | 192.168.1.255 || NTP Server | 42 | Time servers | time.example.com || Lease Time | 51 | Lease duration | 86400 seconds || Message Type| 53 | DHCP message type | 1-8 || Server ID | 54 | DHCP server identifier | 192.168.1.1 || Parameter Req| 55 | Parameter request list | 1,3,6,15,28 || Renewal T1 | 58 | Renewal time | 43200 seconds || Rebinding T2| 59 | Rebinding time | 75600 seconds |
+------------------------------------------------------------------+11.4 DHCP Lease Process
Section titled “11.4 DHCP Lease Process”+------------------------------------------------------------------+| DHCP Lease Lifecycle |+------------------------------------------------------------------+
Lease Timeline:+------------------------------------------------------------------+
T0: IP Assigned | | 50% of lease time (T1) vT1: Renewal Attempt | | If ACK: Lease renewed | If no response: Continue using IP | | 87.5% of lease time (T2) vT2: Rebinding | | Broadcast to ANY server | If ACK: Continue | If NAK or no response: Start DORA | | 100% of lease time vT3: Lease Expired | | Must stop using IP | Start DORA process
Lease Renewal States:+------------------------------------------------------------------+
1. BOUND: +------------------------------------------------------------------+ | IP address successfully assigned | | Can use IP for duration of lease | +------------------------------------------------------------------+
2. RENEWING: +------------------------------------------------------------------+ | T1 reached (50% of lease) | | Unicast to server to renew | | Can continue using IP while waiting | +------------------------------------------------------------------+
3. REBINDING: +------------------------------------------------------------------+ | T2 reached (87.5% of lease) | | Broadcast to any DHCP server | | Last attempt before expiration | +------------------------------------------------------------------+
4. REBOOTING: +------------------------------------------------------------------+ | Lease expired or client restarted | | Broadcast REQUEST for previously assigned IP | | If NAK, start DORA | +------------------------------------------------------------------+
Default Lease Times:+------------------------------------------------------------------+
| Service | Default Lease | Maximum Lease ||-----------------|---------------|---------------|| Home router | 24 hours | 24 hours || Enterprise | 8 hours | 24 hours || Server | 24 hours | 7 days || Mobile device | 24 hours | 7 days |
+------------------------------------------------------------------+11.5 DHCP Configuration
Section titled “11.5 DHCP Configuration”+------------------------------------------------------------------+| DHCP Server Configuration |+------------------------------------------------------------------+
ISC DHCP Server (dhcpd):+------------------------------------------------------------------+
# /etc/dhcpd.conf
# Global settingsdefault-lease-time 86400; # 1 daymax-lease-time 172800; # 2 daysauthoritative; # This is authoritative server
# DNS settingsoption domain-name "example.com";option domain-name-servers 8.8.8.8, 8.8.4.4;option ntp-servers time.example.com;
# Subnet declarationsubnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.50 192.168.1.200; # Address pool option routers 192.168.1.1; # Default gateway option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option ntp-servers 192.168.1.1;
# Reserved addresses host printer { hardware ethernet 00:1a:2b:3c:4d:5e; fixed-address 192.168.1.50; }}
# Another subnetsubnet 10.0.0.0 netmask 255.255.0.0 { range 10.0.1.10 10.0.1.250; option routers 10.0.0.1; option domain-name-servers 10.0.0.53;}
# Failover configurationfailover peer "dhcp-failover" { primary; address 192.168.1.1; port 519; peer address 192.168.1.2; max-response-delay 30; max-unacked-updates 10; mclt 1800; split 128; load balance max seconds 3;}
Start DHCP Server:+------------------------------------------------------------------+
# Arch Linuxsudo systemctl enable dhcpd4sudo systemctl start dhcpd4
# Check statussudo systemctl status dhcpd4
DHCP Client Configuration:+------------------------------------------------------------------+
systemd-networkd:+------------------------------------------------------------------+
# /etc/systemd/network/eth0.network[Match]Name=eth0
[Network]DHCP=ipv4
[DHCP]UseDNS=yesUseRoutes=yesUseGateway=yes
dhcpcd:+------------------------------------------------------------------+
# Installsudo pacman -S dhcpcd
# Enablesudo systemctl enable dhcpcdsudo systemctl start dhcpcd
# For specific interfacesudo systemctl enable dhcpcd@eth0sudo systemctl start dhcpcd@eth0
View DHCP Lease:+------------------------------------------------------------------+
# Current leasescat /var/lib/dhcp/dhcpd.leases
# New formatcat /var/lib/dhcp/dhcpd.leases~
# Client leasescat /var/lib/dhcpcd/eth0.lease
+------------------------------------------------------------------+11.6 DHCP Relay
Section titled “11.6 DHCP Relay”+------------------------------------------------------------------+| DHCP Relay Agent |+------------------------------------------------------------------+
Problem:+------------------------------------------------------------------+
DHCP broadcast doesn't cross routers by default+------------------------------------------------------------------+
Solution: DHCP Relay Agent (IP Helper)+------------------------------------------------------------------+
Router receives broadcast and forwards to DHCP server as unicast
Configuration (Cisco):+------------------------------------------------------------------+
interface GigabitEthernet0/0 ip helper-address 192.168.1.100
Multiple DHCP servers:+------------------------------------------------------------------+
interface GigabitEthernet0/0 ip helper-address 192.168.1.100 ip helper-address 192.168.1.101
Linux DHCP Relay (relayd):+------------------------------------------------------------------+
# Installsudo pacman -S dhcp
# Run relaysudo dhcrelay -4 -i eth0 192.168.1.100
# With multiple serverssudo dhcrelay -4 -i eth0 192.168.1.100 192.168.1.101
+------------------------------------------------------------------+11.7 DHCP Security
Section titled “11.7 DHCP Security”+------------------------------------------------------------------+| DHCP Security |+------------------------------------------------------------------+
Attacks:+------------------------------------------------------------------+
1. Rogue DHCP Server:+------------------------------------------------------------------+
Attack: Malicious DHCP server responds to requestsResult: Users get wrong IP, gateway, DNS
Defense:+------------------------------------------------------------------+| - Port security on switches || - DHCP snooping (Cisco) || - 802.1X authentication |+------------------------------------------------------------------+
2. DHCP Starvation:+------------------------------------------------------------------+
Attack: Request all available IPsResult: Legitimate users can't get IPs
Defense:+------------------------------------------------------------------+| - Rate limiting || - Port security || - DHCP snooping |+------------------------------------------------------------------+
DHCP Snooping (Cisco):+------------------------------------------------------------------+
# Enable on switchip dhcp snooping
# On specific VLANip dhcp snooping vlan 10,20
# Configure trusted portsinterface GigabitEthernet0/1 ip dhcp snooping trust
# Verifyshow ip dhcp snooping
+------------------------------------------------------------------+Summary
Section titled “Summary”In this chapter, you learned:
- DHCP fundamentals and why use it
- DORA process in detail
- DHCP message types
- Lease lifecycle
- Server and client configuration
- DHCP relay
- DHCP security
Next Chapter
Section titled “Next Chapter”Last Updated: February 2026