Kahibaro
Discord Login Register

13.8 DHCP

Overview

Dynamic Host Configuration Protocol, or DHCP, is a protocol that automatically gives devices on a network their IP configuration. Instead of manually typing an IP address, subnet mask, default gateway, and DNS servers on every computer, a DHCP server can assign those values automatically when a device joins the network.

DHCP operates at the application layer but its job is to help configure lower layer parameters, mainly IP settings for the network layer. It is one of the most important services in modern IP networks because it makes large scale network management practical and reduces configuration errors.

Why DHCP Exists

In small networks with a few devices, you can assign IP addresses manually, a method called static addressing. In a network with hundreds or thousands of devices, manual configuration becomes slow and very error prone. Overlapping addresses, wrong subnet masks, or incorrect default gateways can easily break connectivity.

DHCP solves these problems by centralizing IP configuration. A single DHCP server or a small set of servers keeps track of which addresses are in use and which are free, then hands out correct settings to clients when they join the network.

DHCP also simplifies changes. If you want to change DNS servers or the default gateway for an entire network, you only need to update the DHCP configuration and then let clients renew their leases, instead of touching every device.

Basic DHCP Roles

In DHCP, devices play specific roles. The DHCP client is the device that needs configuration. This can be a PC, phone, printer, or any networked device. The DHCP server is a device or service that owns and manages pools of IP addresses and other configuration settings. There can also be a DHCP relay, which is a device, typically a router, that forwards DHCP messages between clients and servers that are not on the same local network.

Clients usually have DHCP enabled by default in their operating systems. The moment they connect to a network, they begin the DHCP process to obtain the configuration they need.

DHCP Lease Concept

DHCP does not just give away IP addresses permanently. Instead, it lends them for a certain amount of time. This is called a lease. The DHCP server defines a lease time, for example 8 hours, 24 hours, or several days. During the lease, the client is allowed to use the given IP address.

When the lease is close to expiring, the client tries to renew it with the same server so it can keep using its current address. If the client shuts down or leaves the network, that address will eventually return to the pool when the lease expires. This dynamic reuse of addresses is important, especially in environments where many devices connect and disconnect, such as Wi Fi networks.

A lease usually includes more than just an address. It includes many configuration values, such as subnet mask, default gateway, and one or more DNS servers. All of these are considered part of the lease information.

The DHCP DORA Process

The DHCP process between client and server commonly uses four main steps. These steps are often remembered by the acronym DORA, which stands for Discover, Offer, Request, and Acknowledge.

In the Discover step, the client does not yet have an IP address. It sends a broadcast message to the local network, asking if any DHCP server is available. Since it does not know the server address, it uses broadcast so any listening server can hear the request.

In the Offer step, one or more DHCP servers respond with a unicast or broadcast message to the client. Each server that responds proposes an IP address and related configuration. This is the offer. The offer includes information such as the proposed IP, the subnet mask, the default gateway, the DNS servers, and the lease time.

In the Request step, the client chooses one of the offers, usually the first one it receives, and sends a DHCP Request message to indicate which server and IP address it has selected. This message confirms the client’s choice and asks that server to finalize the assignment.

In the Acknowledge step, the selected server sends a DHCP Acknowledge message, often abbreviated DHCP ACK. This message includes the final configuration, confirming that the IP address and related settings are now officially leased to that client for the given time.

The DORA exchange allows clients to get configuration information automatically without manual setup. It also gives the server a chance to track which clients have which addresses.

Important rule: The DORA sequence, Discover → Offer → Request → Acknowledge, is the standard order of DHCP address assignment and is critical for automatic IP configuration.

DHCP Messages and Transport

Although DHCP is an application layer protocol, the transport layer details are important to understand its behavior. DHCP uses the User Datagram Protocol (UDP). The client sends messages from UDP port 68 and the server listens on UDP port 67.

When a new client connects and sends a Discover, it has no valid IP address, so the IP source is usually 0.0.0.0 and the destination is the local broadcast address. This broadcast behavior is necessary because the client does not yet know the IP of the DHCP server. The use of UDP, which is connectionless, matches this pattern well because the client sends messages without establishing a session first.

DHCP Scopes and Pools

On the DHCP server, IP addresses are organized into scopes or pools. A scope is a defined range of IP addresses that the server can hand out on a particular network segment. For example, a scope could be from 192.168.1.100 to 192.168.1.200. When a new client requests an address, the server picks a free address from this range.

A scope is usually associated with a specific subnet. The administrator configures the subnet mask, the default gateway for that subnet, and other parameters like DNS servers and lease time. The server uses this information when creating offers.

Typical scope definition might look like this:

SettingExample value
Network192.168.1.0
Subnet mask255.255.255.0
Scope range192.168.1.100–200
Default gateway192.168.1.1
DNS server8.8.8.8
Lease time24 hours

The server will not offer addresses outside the scope. Proper planning of scopes is a part of IP planning and subnetting, which are covered elsewhere in the course.

DHCP Options

DHCP can deliver many different configuration details besides the IP address and subnet mask. These are sent as DHCP options. Each option has a specific number and meaning. Some of the most important options for typical clients are the default gateway, the DNS server addresses, the domain name, and the lease time.

A simplified table of common DHCP options looks like this:

OptionTypical use
RouterDefault gateway address
DNS serverIP of DNS servers
Domain nameLocal domain suffix, for example lab.local
Lease timeDuration of the IP address lease

By using options, administrators can centralize almost all basic network settings on the DHCP server. Clients then receive all needed information during the DHCP exchange, with no manual input.

DHCP Reservation

Sometimes, a device needs a fixed IP address but we still want to manage it through the DHCP server. An example is a printer, a server, or a network camera. Instead of configuring a static IP on the device itself, the administrator can create a DHCP reservation.

A reservation maps a specific client identifier, usually the MAC address of the network interface, to a specific IP address. When that client requests an address, the DHCP server always offers the reserved IP instead of a random one from the pool.

This approach combines the benefits of a stable IP with centralized management. It also avoids accidental duplication because the DHCP server will not assign that reserved address to any other device.

DHCP Relay

DHCP was designed to work on a local broadcast domain. The initial Discover from the client is a broadcast, so routers do not normally forward it across networks. However, in many real networks there is a centralized DHCP server in a data center, and clients are spread across many different subnets.

A DHCP relay solves this problem. A relay agent is configured on a router or Layer 3 device that connects the client’s subnet to the network where the DHCP server resides. When the router sees a DHCP broadcast, it does not drop it. Instead, it captures the message, wraps it in a unicast packet, and forwards it directly to the configured DHCP server address.

The server responds to the relay instead of directly to the client. The relay then sends the response back into the local subnet as appropriate, so the client can receive it. From the client’s point of view, the process looks like normal DHCP. The presence of the relay is invisible to the end device.

DHCP Lease Renewal

A DHCP client does not wait until the very last second to renew its lease. Instead, it begins renewal early. While the detailed timing is beyond beginner level, it is useful to understand the idea. The client uses the Request and Acknowledge steps again to ask the same server to extend the life of its current address.

If the server is reachable and accepts the renewal, the client keeps its address for a new lease period. If the server is not reachable or refuses, the client may try again later or attempt to contact any available DHCP server. During this time, the client may continue to use its current address as long as the lease is not yet expired.

This renewal mechanism provides stability. Devices tend to keep the same IP address over time, even though DHCP is dynamic. It also allows servers to eventually reclaim addresses from devices that have disappeared.

DHCP and Address Conflicts

One of DHCP’s key benefits is the reduction of address conflicts, which happen when two devices try to use the same IP. The server keeps a record of active leases, so it will usually not assign the same address twice.

However, problems can still occur, for example if a device is misconfigured with a static IP that belongs to the DHCP scope. Some clients perform a simple check before fully using the address, such as sending a small probe, to detect whether the address is already in use. If an address conflict is detected, the client may request a different address.

To prevent conflicts, it is important to separate static address ranges and DHCP scopes carefully. For example, an administrator might reserve the first part of a subnet for static addresses and configure the DHCP scope to start at a higher address.

DHCP in Home and Enterprise Networks

In most home networks, the home router or gateway device acts as the DHCP server. When you connect a new phone or laptop to your home Wi Fi, the router automatically gives it an address from an internal private range and provides the default gateway and DNS settings. The user usually never sees or configures DHCP directly.

In enterprise networks, DHCP is often handled by dedicated servers or by services on network operating systems. Scopes are defined per subnet. DHCP relay is commonly used so that a central service can serve many remote locations. Reservations and tailored options are used to give specific devices special settings while still using the same infrastructure.

DHCP is also used in more specialized environments, such as IP phones and some network devices, which use specific options to automatically discover their management servers. The details of those advanced uses are beyond an introductory chapter, but the underlying mechanism is the same DORA process.

DHCP Security Considerations

By design, DHCP trusts requests and offers on the local network. This can create risks. A malicious or misconfigured device could act as a rogue DHCP server and hand out incorrect IP settings, such as a fake default gateway, which can lead to man in the middle attacks or loss of connectivity.

In enterprise environments, network administrators can use security features on switches to limit which ports are allowed to send DHCP server messages. Only trusted ports, where the real servers or relays are connected, are allowed to act as DHCP servers. Clients, connected on untrusted ports, can only send DHCP client messages.

From a user perspective, the main point is that DHCP is automatic but also powerful. Whoever controls DHCP for a network has significant influence on how traffic is routed and resolved, because they control default gateways and DNS settings distributed to all clients.

Summary

DHCP is the standard way that most IP devices receive their configuration. It automates the assignment of IP addresses through a lease mechanism, using a simple sequence of messages remembered as DORA, and operates over UDP on well known ports. By centralizing address management into scopes and pools, it reduces errors and administration effort, supports both dynamic addresses and fixed reservations, and works across multiple networks with the help of relays. Understanding DHCP is essential to understanding how devices join and function in modern IP networks.

Views: 47

Comments

Please login to add a comment.

Don't have an account? Register now!