Parameters Required for IP Configuration
A device communicating on an IP network needs a set of configuration parameters. One is a unique . An IPv4 device also needs a 32-bit and the address of a , usually a router that forwards traffic to other networks. It also needs the address of a for resolving domain names.
In a small, static network, an administrator can configure these parameters manually. This is static IP addressing. In a corporate office, university campus, or public Wi-Fi network, devices constantly join and leave. Manually assigning and tracking addresses to avoid conflicts requires work and creates opportunities for mistakes. An end user should not have to enter these values whenever a phone or laptop joins a new network.
The automatically delivers these parameters. It uses UDP, with client and server messages using ports 68 and 67 respectively. DHCPv4 carries parameters in the BOOTP-compatible header and in a variable-length options field.
DHCP as an Automatic Configuration Protocol
DHCP is an application-layer protocol that automates configuration on an IP network. A DHCP server assigns IP addresses and other parameters when a device joins the network. The client uses the resulting lease and can renew it before the specified time expires. The server records the client binding, lease time, and parameters sent in its reply. The binding associates the address with a client identifier and a network scope, which lets the server select a suitable pool.
The device requesting configuration is a DHCP client. The system assigning the configuration is the DHCP server. In a home network, a router often acts as both default gateway and DHCP server. In a larger network, the server can run as a dedicated service, while a relay agent handles messages from other subnets.
Core Benefits of DHCP
- Centralized management and automation: DHCP allows an administrator to configure an address pool and client parameters from one server. A settings change can then cover many devices, and the server records assigned bindings.
- Dynamic IP addressing: The server assigns or leases addresses from a defined pool. After a lease ends, an address can return to the pool and be assigned to another device according to server state. A client should not use the address outside its valid period. The server can mark an address unavailable after a conflict report.
- Error reduction: Automation limits manual configuration errors such as typing mistakes and IP address conflicts. A conflict occurs when two devices use the same address on one network. The server can check pool state and respond when a client reports an address in use.
- Mobility and ease of use: Connecting a laptop or phone to a new network can start automatic DHCP configuration. The user receives the parameters without entering the address, mask, or servers. The process also works when a device changes an access point or subnet, provided the new network offers DHCP service.
The DORA Process: Four DHCP Messages
A typical initial client configuration uses a four-message exchange. The name DORA comes from Discover, Offer, Request, and Acknowledge. The exchange can take place directly on a subnet or through a relay agent. The messages carry a transaction identifier so the client can match a reply to its request.
- D - Discover (Client discovery)
When a client joins a network without an IP address, it sends a DHCPDISCOVER message to find a server. On a directly connected network, it uses destination IP and destination MAC . The source IP is . The message contains a transaction identifier, the client hardware address, and flags that indicate how the reply should be delivered. If a relay agent is present, the client broadcast reaches that agent.
- O - Offer (Server offer)
A DHCP server that receives DHCPDISCOVER directly or through a relay can respond with a DHCPOFFER. The offer associates a proposed address with the transaction identifier and carries configuration that can include:
- An available IP address from the server's pool.
- The subnet mask for the network.
- The address of the default gateway (router).
- The address of the DNS server.
- The lease duration: the amount of time the client is allowed to use this IP address.
The delivery method depends on the flags field, the message addresses, and the presence of a relay agent. In a network with multiple DHCP servers, the client can receive several offers. The values must match the subnet and the server's allocation policy. The client compares the offers before sending the selected server identifier in DHCPREQUEST.
- R - Request (Client request)
The client selects an offer according to its policy and sends DHCPREQUEST. During the initial exchange, the message is broadcast and contains the selected server identifier and requested IP address. It can also include the client identifier and a parameter request list. Other servers see that their offers were not selected and can release the proposed addresses. The same message type is used for renewal, when it can be sent by unicast.
- A - Acknowledge (Server acknowledgment)
The selected server replies with DHCPACK. It confirms the IP address, other parameters, and lease duration. The server records the client binding in its allocation state. The client can then use the configuration, and the address remains unavailable for other allocations according to server policy and lease time. If the configuration is invalid for the subnet, the server can respond with DHCPNAK. The client must then stop using the offered configuration and restart discovery.
DHCP Lease Management
DHCP assigns IP addresses for a specific period known as a . The client must renew the lease before it expires, while the server uses the lease state to manage its address pool. Option 51 carries the lease time, and Options 58 and 59 can carry the T1 and T2 times.
The Lease Renewal Process
If the client is to keep using the IP address, it begins renewal before the lease expires. A typical client performs these actions automatically:
- T1 Timer (Renewal timer): At T1, normally the default of half the lease time, the client sends a unicast DHCPREQUEST to the server that granted the lease. It requests an extension of the current binding.
- Server acknowledgment: If the server replies with DHCPACK, the client updates the lease time and keeps the configuration. The reply can also contain new parameters in DHCP options.
- T2 Timer (Rebinding timer): If the client receives no response by T2, normally 87.5% of the lease time, it enters the "rebinding" state. It sends DHCPREQUEST as a broadcast or through a relay to obtain a response from any available server.
Lease Expiration and Release
If a client fails to renew its lease before it expires, it stops using the address and starts obtaining configuration again. It can begin the DORA process to receive a new address. The server reclaims the old address according to its lease state. Communication using the old address should end before the new configuration is used. A client can retain other local settings while it waits for a new valid lease.
A client that ends its use of the network can send a DHCPRELEASE message to the server. It informs the server that the client releases the IP address. The server can then mark the address available without waiting for the lease to end and assign it to another client.
Advanced DHCP Concepts
The DORA process describes initial client configuration. DHCP also includes functions for routed networks, address reservations, and additional configuration parameters. These functions use the same messages and header fields while changing how the server and pool are selected.
- DHCP Relay Agent
- DHCPDISCOVER messages are broadcasts confined to a local segment, and a router does not forward them as ordinary IP traffic. Several subnets can still use one server through a .
A router or dedicated server listens for client requests and forwards them to the DHCP server on the server port. It sets the giaddr field and can add the Relay Agent Information option. The server uses the interface or subnet information to select the correct pool. The response returns through the relay to the client, which receives it on the client port.
- Address Reservations
- An administrator can create an address reservation for a printer, server, or other device. A reservation maps a client identifier, often a MAC address or Client Identifier option, to a specific IP address in the server configuration. When the client sends a request with that identifier, the server can offer the assigned address. This combines centralized management with a predictable address, provided the identifier matches the client configuration.
- DHCP Options
- DHCP can be extended through a system of options. The variable-length options field carries parameters beyond the IP address, subnet mask, gateway, and DNS. An administrator can provide a domain name, an NTP (Network Time Protocol) server address, a TFTP server address for network booting, and vendor-specific settings. The IANA registry and related documents define the option codes. A client can list desired options through a parameter request list. A device with an existing address can use DHCPINFORM to request options without asking for a lease.