Elective Network and System Administration

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:

  1. Discover: The client broadcasts a DHCP Discover message to locate available DHCP servers.
  2. Offer: Servers respond with a DHCP Offer, proposing an available IP address and lease time.
  3. Request: The client selects an offer and broadcasts a DHCP Request to accept it.
  4. Acknowledge: The server confirms the assignment with a DHCP Acknowledge and provides additional configuration (e.g., DNS, gateway).

Key DHCP Components

DHCP ClientDHCP Discover (Broadcast)DHCP Relay AgentDHCP Discover (Forwarded)DHCP ServerDHCP Offer (Unicast)Network DevicesDHCP Acknowledge (Unicast)
DHCP message flow across subnets with a relay agent (Ncell’s Wi-Fi example)

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.100 to 192.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.100 to 192.168.1.200
  • Pool: 192.168.1.100 to 192.168.1.190 (leaving 192.168.1.191-200 for 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.100 to 10.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
08162431IP Address32 bitsSubnet Mask32 bitsDefault Gateway32 bitsDNS Servers64 bitsLease Time16 bits
DHCP-assigned configuration for a Ncell hotspot user (10.0.0.105)

Worked Example: Assigning an IP to a User

  1. A user’s phone broadcasts a DHCP Discover.
  2. Ncell’s DHCP server responds with an Offer of 10.0.0.105.
  3. The phone accepts via DHCP Request.
  4. The server confirms with DHCP Acknowledge and provides DNS/gateway details.
  5. 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

  1. 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.
  2. 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.
  3. 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.100 to 192.168.1.200). The lease time is typically short (e.g., 12 hours) to allow quick reallocation if you disconnect.
  4. 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.

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:

  1. 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
      
  2. Inspect Scope Configuration:

    • Ensure the scope range (192.168.10.100 to 192.168.10.200) isn’t exhausted. Check logs:
      sudo tail -f /var/log/syslog | grep dhcpd
      
  3. Test Client Connectivity:

    • On the laptop, release and renew the DHCP lease:
      sudo ipconfig /release  # Windows
      sudo dhclient -r        # Linux
      sudo dhclient           # Linux (renew)
      
  4. 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

  1. 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.
  2. 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.
  3. Reservations: Know when to use DHCP reservations (e.g., for servers, printers) vs. dynamic assignment (e.g., laptops, phones).
  4. 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.
  5. 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 --> Idle

Caption: 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…