Network and System AdministrationUnit 411 min read
DHCP: Leases, Scopes, and Client-Server Workflow
Unit 4 of Network and System Administration covers the Dynamic Host Configuration Protocol (DHCP), explaining how devices automatically obtain IP addresses, subnet masks, default gateways, and DNS servers from a central server, its configuration (scopes, pools, reservations), and troubleshooting common issues.
TAKEAWAYS:
- DHCP automates IP assignment, reducing manual configuration errors and saving time in large networks.
- A DHCP server allocates IP addresses from a predefined scope (range) and renews leases when they expire.
- Clients use DORA (Discover, Offer, Request, Acknowledge) to negotiate an IP lease with the server.
- DHCP reservations assign fixed IPs to specific devices (e.g., printers, servers) while allowing flexibility for others.
- Misconfigurations (e.g., overlapping scopes, incorrect lease times) can cause IP conflicts or network downtime.
- DHCP relay agents extend DHCP service across subnets or routers.
What is DHCP?
The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used to automatically assign IP addresses and other network configuration parameters (e.g., subnet mask, default gateway, DNS servers) to devices on a network. Without DHCP, administrators must manually configure each device, which is error-prone and time-consuming in large networks.
Why Use DHCP?
- Efficiency: Eliminates manual IP assignment.
- Flexibility: Reuses IPs when devices disconnect.
- Centralized Management: Configure settings once on the DHCP server.
- Scalability: Works seamlessly in networks with hundreds or thousands of devices.
How DHCP Works: The DORA Process
DHCP operates using a four-step handshake between a client (e.g., laptop, smartphone) and a server. This is visualized as:
sequenceDiagram
participant Client as DHCP Client
participant Server as DHCP Server
Client->>Server: 1. DHCP Discover (Broadcast)
Server->>Client: 2. DHCP Offer (Unicast)
Client->>Server: 3. DHCP Request (Broadcast)
Server->>Client: 4. DHCP Acknowledge (Unicast)Step-by-Step Breakdown:
- Discover: The client broadcasts a
DHCP Discovermessage to locate available DHCP servers. - Offer: Servers respond with a
DHCP Offer, proposing an available IP address and lease time. - Request: The client selects an offer and broadcasts a
DHCP Requestto accept it. - Acknowledge: The server confirms the assignment with a
DHCP Acknowledgeand provides additional configuration (e.g., DNS, gateway).
Key DHCP Components
1. DHCP Scope
A scope defines the range of IP addresses a DHCP server can assign. It includes:
- IP Address Range: Start and end of the pool (e.g.,
192.168.1.100to192.168.1.200). - Subnet Mask: Defines the network portion of the IP (e.g.,
255.255.255.0). - Default Gateway: The router’s IP for internet access (e.g.,
192.168.1.1). - DNS Servers: IP addresses of DNS resolvers (e.g.,
8.8.8.8,8.8.4.4). - Lease Time: Duration the IP is assigned (e.g., 8 hours, 24 hours, or indefinitely).
2. DHCP Pool
A subset of the scope range reserved for dynamic assignment. For example:
- Scope:
192.168.1.100to192.168.1.200 - Pool:
192.168.1.100to192.168.1.190(leaving192.168.1.191-200for exclusions).
3. DHCP Reservations
Assigns a fixed IP to a specific device using its MAC address. Example:
| Device | MAC Address | Reserved IP |
|---|---|---|
| Printer | 00:1A:2B:3C:4D:5E |
192.168.1.5 |
| Server | AA:BB:CC:DD:EE:FF |
192.168.1.10 |
4. DHCP Relay Agent
Extends DHCP service across routers or subnets. Without a relay, DHCP requests are limited to the local subnet. Example:
[Client Subnet] --(Router)--> [DHCP Server Subnet]
The relay forwards DHCP Discover messages to the server and returns DHCP Offer responses to the client.
DHCP Configuration Example: Ncell’s Wi-Fi Network
Ncell uses DHCP to assign IPs to thousands of mobile hotspot users daily. Suppose Ncell’s router has:
- Scope:
10.0.0.100to10.0.0.200 - Subnet Mask:
255.255.255.0 - Default Gateway:
10.0.0.1 - DNS Servers:
8.8.8.8,1.1.1.1 - Lease Time: 24 hours
Worked Example: Assigning an IP to a User
- A user’s phone broadcasts a
DHCP Discover. - Ncell’s DHCP server responds with an
Offerof10.0.0.105. - The phone accepts via
DHCP Request. - The server confirms with
DHCP Acknowledgeand provides DNS/gateway details. - After 24 hours, the phone renews the lease automatically.
DHCP vs. Static IP Assignment
| Feature | DHCP | Static IP |
|---|---|---|
| Assignment | Automatic, dynamic | Manual, fixed |
| Ease of Use | High (no manual config) | Low (requires admin access) |
| Scalability | Excellent (thousands of devices) | Poor (limited to configured IPs) |
| Flexibility | High (reuses IPs) | Low (wasted if device is offline) |
| Use Case | Home networks, offices, ISPs | Servers, printers, routers |
Common DHCP Issues and Solutions
| Issue | Cause | Solution |
|---|---|---|
| IP Conflict | Two devices assigned the same IP | Check DHCP logs; exclude conflicting IP. |
| No IP Assignment | DHCP server down or misconfigured scope | Verify server status; expand scope range. |
| Slow Network Performance | Exhausted DHCP pool | Increase pool size or reduce lease time. |
| Lease Not Renewing | Incorrect lease time or firewall blocking DHCP | Adjust lease time; check firewall rules. |
In the Real World
eSewa and Khalti (Nepal)
- DHCP Relay Agents: When you connect to eSewa’s or Khalti’s payment gateway via Wi-Fi in a café, the router uses DHCP to assign you an IP. If the café has multiple subnets (e.g., for staff and customers), a DHCP relay ensures your device gets an IP even if it’s not on the same subnet as the DHCP server.
Daraz Order Fulfillment (Logistics)
- DHCP Reservations: Daraz’s warehouse management system assigns fixed IPs to critical devices like barcode scanners and inventory trackers. These devices use DHCP reservations to ensure they always get the same IP for reliable communication with the central server.
NTC and Ncell Network Management
- DHCP Scopes for ISPs: NTC and Ncell use DHCP to dynamically assign IPs to broadband users. For example, when you log in to your home Wi-Fi, the router’s DHCP server assigns you an IP from its scope (e.g.,
192.168.1.100to192.168.1.200). The lease time is typically short (e.g., 12 hours) to allow quick reallocation if you disconnect.
- DHCP Scopes for ISPs: NTC and Ncell use DHCP to dynamically assign IPs to broadband users. For example, when you log in to your home Wi-Fi, the router’s DHCP server assigns you an IP from its scope (e.g.,
Bank ATMs and Security Systems
- Static IPs for Critical Devices: Banks use static IPs for ATMs and security cameras, but DHCP is used for employee laptops and printers. For example, an ATM at a Nepal SBI branch might have a reserved IP (
192.168.10.10) to ensure uninterrupted communication with the bank’s core system.
- Static IPs for Critical Devices: Banks use static IPs for ATMs and security cameras, but DHCP is used for employee laptops and printers. For example, an ATM at a Nepal SBI branch might have a reserved IP (
DHCP Server Configuration (Linux Example)
To configure a DHCP server on Linux (e.g., Ubuntu), edit the /etc/dhcp/dhcpd.conf file:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 2400; # 40 minutes
max-lease-time 7200; # 2 hours
}
```mermaid
stateDiagram-v2
[*] --> LeaseActive
LeaseActive --> LeaseHalf: 50% time elapsed
LeaseHalf --> LeaseExpiring: 75% time elapsed
LeaseExpiring --> RenewAttempt: Lease expires
RenewAttempt --> LeaseActive: Success
RenewAttempt --> [*]: Failure
state LeaseActive {
[IP: 192.168.1.105\nLease: 24h] : Active
}
state RenewAttempt {
[DHCP Request\nRetransmit] : 3 attempts
}
DHCP lease state machine (Linux client behavior during renewal)
Reservation for a printer
host printer { hardware ethernet 00:1A:2B:3C:4D:5E; fixed-address 192.168.1.5; }
Start the DHCP service with:
```bash
sudo systemctl start isc-dhcp-server
DHCP in Action: Troubleshooting a Failed Lease
Suppose a student’s laptop fails to get an IP from TU’s campus Wi-Fi. Here’s how to diagnose it:
Check DHCP Server Status:
- Verify the DHCP service is running:
sudo systemctl status isc-dhcp-server - If down, restart it:
sudo systemctl restart isc-dhcp-server
- Verify the DHCP service is running:
Inspect Scope Configuration:
- Ensure the scope range (
192.168.10.100to192.168.10.200) isn’t exhausted. Check logs:sudo tail -f /var/log/syslog | grep dhcpd
- Ensure the scope range (
Test Client Connectivity:
- On the laptop, release and renew the DHCP lease:
sudo ipconfig /release # Windows sudo dhclient -r # Linux sudo dhclient # Linux (renew)
- On the laptop, release and renew the DHCP lease:
Firewall or VLAN Issues:
- Ensure UDP ports 67 (server) and 68 (client) are open. If the network uses VLANs, the DHCP relay must be configured correctly.
Exam Tip
- Understand the DORA Process: Be ready to draw or describe the four-step handshake in exams. Questions often ask how a client gets an IP or why a lease might fail.
- Scope vs. Pool: Differentiate between a scope (entire range) and a pool (usable subset). Exams may ask you to calculate how many IPs are left in a pool.
- Reservations: Know when to use DHCP reservations (e.g., for servers, printers) vs. dynamic assignment (e.g., laptops, phones).
- Troubleshooting: Practice diagnosing scenarios like:
- "A device gets an IP but cannot access the internet. What could be wrong?" Answer: Likely a misconfigured default gateway in the DHCP scope.
- "All IPs in the scope are exhausted. What should the admin do?" Answer: Extend the scope range or reduce the lease time.
- Real-World Applications: Expect questions linking DHCP to ISP networks (Ncell/NTC), corporate Wi-Fi (eSewa offices), or home routers. For example:
- "How does Daraz’s warehouse use DHCP for inventory tracking?" Answer: Dynamic assignment for mobile devices + reservations for fixed scanners.
stateDiagram-v2
[*] --> Idle
Idle --> Discover: Client broadcasts
Discover --> Offer: Server responds
Offer --> Request: Client accepts
Request --> Acknowledge: Server confirms
Acknowledge --> Active: IP assigned
Active --> Renew: Lease expires
Renew --> Acknowledge: Lease renewed
Active --> Release: Client releases IP
Release --> IdleCaption: DHCP Client State Machine. Shows how a device transitions from discovering an IP to renewing or releasing it.
Based on the TU BSc CSIT syllabus for Network and System Administration, unit 4.
Discussion
Loading…