Information Technology

DHCP (Dynamic Host Configuration Protocol)

29 Aug 2023

DHCP, or Dynamic Host Configuration Protocol, is a network protocol used to automatically assign and manage IP (Internet Protocol) addresses and other network configuration parameters to devices within a TCP/IP-based network. DHCP simplifies the process of configuring network settings for computers, smartphones, printers, and other devices on a network. Here are the key components and functions of DHCP :

  • IP Address Allocation : DHCP allows for the automatic allocation of IP addresses to devices on a network. When a device connects to the network and requests an IP address, the DHCP server assigns an available IP address from a predefined pool to the device.
    • An “address pool” in Cisco terminology (or “scope” on Windows/another platform) refers to a range of IP addresses that a DHCP server manages and assigns to client devices.
  • Subnet Mask : Along with an IP address, DHCP provides the subnet mask, which defines the network’s address range and helps devices determine which other devices are on the same local network or subnet.
  • Default Gateway : DHCP can provide the IP address of the default gateway (router) that devices should use to access other networks or the internet. This is crucial for routing traffic beyond the local network.
  • DNS Server Addresses : DHCP can also provide the IP addresses of DNS (Domain Name System) servers to devices. DNS servers are responsible for resolving human-readable domain names (like www.example.com) into IP addresses, enabling devices to access websites and services using domain names.
  • Lease Duration : DHCP leases are not permanent; instead, they are temporary assignments of IP addresses. DHCP servers can specify a lease duration, after which the device must renew its lease. This allows IP addresses to be efficiently reused as devices come and go on the network.
    • A “lease” refers to the temporary assignment of an IP address and associated network configuration parameters by a DHCP server to a client device. When a device connects to a network and requests an IP address from a DHCP server, the server leases an IP address to the device for a specified period of time. This lease duration defines how long the device is allowed to use that particular IP address and network configuration.
  • Automatic Configuration : DHCP eliminates the need for manual IP address configuration, which can be error-prone and time-consuming, especially in large networks. It streamlines the process of connecting new devices to the network.
  • Centralized Management : Network administrators can centrally manage IP address assignments and configurations from a DHCP server. This makes it easier to make changes or updates to network settings across a large number of devices.

How It Works?

  • Device Initialization :
    • When a device, such as a computer or smartphone, connects to a network (by plugging into an Ethernet port or connecting to a Wi-Fi network), it typically starts with no configured IP address.
  • DHCP Discover (Device to Server) :
    • The device, aware of its lack of IP address, sends a DHCP Discover packet as a broadcast message to the local network segment.
    • In this packet, the device indicates its intention to acquire an IP address and requests DHCP services.
  • DHCP Offer (Server to Device) :
    • A DHCP server on the network receives the DHCP Discover packet.
    • The DHCP server, if configured and authorized to provide IP addresses to clients on that network segment, responds with a DHCP Offer packet.
    • The DHCP Offer packet contains an available IP address from the DHCP server’s pool, along with other configuration parameters such as subnet mask, default gateway, DNS server addresses, and lease duration.
    • Multiple DHCP servers on the network may respond with offers, and the client selects one of the offered IP addresses.
  • DHCP Request (Device to Server) :
    • The device, having received one or more DHCP Offer packets, selects an offered IP address.
    • It sends a DHCP Request packet, indicating its choice of IP address and confirming its request for DHCP services.
  • DHCP Acknowledge (Server to Device) :
    • The DHCP server that initially offered the selected IP address receives the DHCP Request packet.
    • The DHCP server sends a DHCP Acknowledge packet to the device, confirming that it can use the selected IP address and providing the configuration parameters.
    • This acknowledgment finalizes the lease of the IP address to the device.
  • Lease Duration Countdown :
    • The device now has a valid IP address and can use it to communicate on the network.
    • It al notes the lease duration provided by the DHCP server.
  • Lease Renewal (Device to Server) :
    • As the lease expiration time approaches (typically at the halfway point), the device may attempt to renew its lease to continue using the IP address.
    • It sends a DHCP Request packet to the DHCP server requesting lease renewal.
  • Lease Renewal Acknowledge (Server to Device) :
    • If the DHCP server approves the renewal, it sends a DHCP Acknowledge packet to the device, extending the lease duration for the same IP address.
  • Lease Expiration :
    • The device continues to use the leased IP address until the lease duration expires.
    • Once the lease duration expires, the device will stop using the IP address and must either request a lease renewal or obtain a new IP address through the DHCP process if it wishes to remain connected to the network.

DHCP Server Configuration on Cisco Router

1) Enable DHCP server on the interface :

Router(config)# service dhcp <interface-id>

2) Create a DHCP server address pool and enters DHCP pool configuration mode :

Router(config)# ip dhcp pool <name>

3) Specify the network address and subnet mask of the DHCP address pool :

Router(dhcp-config)# network <network-address> <subnet-mask-or-/prefix-length>

4) Specify the IP address of the default router (default gateway) for a DHCP client :

Router(dhcp-config)# default-router 192.168.1.1

5) Specify the IP address of a DNS server that is available to a DHCP client :

Router(dhcp-config)# dns-server 8.8.8.8

6) Specify the domain name for the client :

Router(dhcp-config)# domain-name cisco.com

7) Specify address lease time :

  • The default is a one-day lease.
Router(dhcp-config)# lease <number-of-days> <number-of-hour> <number-of-minutes>

8) Specifies the IP addresses that the DHCP server should not assign to DHCP clients (exclude an IP address from the address pool) :

Router(config)# ip dhcp excluded-address <ip-address>

9) Display address bindings on the DHCP server :

  • Verify that the address pool has not been exhausted.
Router# show ip dhcp binding

10) Displays information about DHCP address pools :

Router# show ip dhcp pool <name>

References