DHCP Configuration Guide
Introduction
Section titled “Introduction”The Dynamic Host Configuration Protocol (DHCP) is a technology used for centralized management and configuration of user IP addresses. Following the RFC 2131 standard, DHCP operates in a client/server communication model, where DHCP clients send requests to DHCP servers. These servers allocate IP addresses to clients with a designated usage period known as the lease time.
This allocation mechanism is suitable for scenarios involving hosts that require temporary network access or cases where the total number of network hosts is substantial, and the available addresses are limited. It is especially useful when hosts do not need a permanent network connection.
Explanation of Principles
Section titled “Explanation of Principles”A typical DHCP network setup involves three primary roles:
- DHCP Server
The DHCP server is responsible for selecting an IP address from an available address pool and assigning it to a DHCP client. Additionally, it can provide other network parameters such as the default gateway address, DNS server addresses, and WINS server addresses. The DHCP server can handle DHCP request packets within its local subnet as well as DHCP request packets forwarded across subnets through DHCP relays.
- DHCP Client
The DHCP client actively sends DHCP request packets using the BOOTP or DHCP protocol to obtain an IP address and other network parameters. Typical DHCP clients include devices like IP phones, personal computers, mobile phones, diskless workstations, and more.
- DHCP Relay
When a DHCP client broadcasts a request packet, DHCP servers within the same subnet can receive and process these requests. However, if the DHCP client and the DHCP server are not within the same subnet, the DHCP server will not directly receive the client’s request. In such cases, a DHCP relay is used to forward the DHCP packets. Unlike traditional IP packet forwarding, the DHCP relay receives DHCP request or response packets, reconstructs new DHCP unicast packets, and forwards them through the Layer 3 network.

IP Address Acquisition Process
Section titled “IP Address Acquisition Process”The DHCP process involves the following fundamental stages:
1.Discovery and Request Stage:
When a device (DHCP client) joins a network or requires reconfiguration of network information, it broadcasts a DHCP Discover message to all devices in the local network. This message is sent to locate available DHCP servers.
2.Offer and Selection Stage:
After one or more DHCP servers within the network receive the DHCP Discover message, they respond with a DHCP Offer broadcast message. This message contains available IP addresses, lease durations, subnet masks, default gateways, and other configuration details.
3.Request and Acknowledgment Stage:
Upon receiving multiple DHCP Offer messages, the DHCP client typically chooses one of them and sends a DHCP Request broadcast message to the chosen server. This indicates the client’s acceptance of the offered configuration from that specific server.
4.Acknowledgment and Lease Stage:
Upon receiving the DHCP Request message from the client, the DHCP server sends a DHCP Acknowledgment broadcast message to confirm the allocation of the IP address and other configuration details. This confirms that the client has successfully acquired the network configuration.
5.Renewal and Release:
Before the lease expires, the client attempts to renew the lease by contacting the DHCP server halfway through the lease duration. If the client no longer requires the configuration or leaves the network, it can send a DHCP Release message to relinquish the allocated IP address and configuration settings.
Configuring the Device as a DHCP Server
Section titled “Configuring the Device as a DHCP Server”DHCP Server Configuration
Section titled “DHCP Server Configuration”| Operation | Command | Description |
|---|---|---|
| Enter the system configuration view | configure terminal | |
| Create a DHCP address pool and enter the DHCP configuration view | dhcp pool name | |
| Configure the dynamic allocation subnet for the DHCP address pool | network ip-address mask | |
| Specify the IP address range for dynamic IP allocation | address-pool ip-address ip-address | |
| Configure the gateway for DHCP clients | routers ip-address | |
| Configure DNS addresses for DHCP clients | dns ip-address | |
| Set the lease duration for dynamically allocated IP addresses | lease-time default-time max-time | |
| Configure the TFTP server address for DHCP clients | tftp-server server-name | |
| Specify the boot file name for DHCP clients | bootfile-name bootfile | |
| Set the next server IP address for DHCP clients | next-server ip-address | |
| Bind the DHCP server to the interface | interface ethernet |
Configuring DHCP Option
Section titled “Configuring DHCP Option”The DHCP server can use the DHCP Option feature to recognize specific vendor information from the DHCP client’s request packets. This allows the server to allocate customized network parameters based on the client’s vendor or specific needs.
1.Create a DHCP Client Classification Group
Define a group that will classify DHCP clients based on specific criteria, such as option 93
dhcp class <name>if-match rule <ID> option 93 hex <value>2.Create an Option Group
Define an option group that will hold the custom DHCP options for the classified clients.Set the required DHCP options within this option group.
Example to configure Option 43 for custom vendor information:
dhcp option-group <ID>option 43 hex <hex-value>Example to configure a tftp server:
tftp-server <ip-address>3.Apply the Option Group to the DHCP Client Classification Group
Bind the option group to the DHCP client classification group, so that clients matching the classification receive the custom options.
dhcp pool <name>class <name> option-group <ID>DHCP Failover Working Principle
Section titled “DHCP Failover Working Principle”The DHCP Failover mechanism ensures high availability and redundancy for DHCP servers, which are critical parts of the network infrastructure. By running multiple DHCP servers simultaneously, the network can continue to function even if one server fails.

The device supports dual DHCP server hot standby, as shown in the diagram. Two core devices each deploy a DHCP server, and when servers are connected to the network via dual network cards, the two DHCP servers can achieve load balancing and failover.
The servers compute a hash value from the client_identifier field in the DHCP request packet, generating a value between 1 and 255.
Based on a configured weight distribution percentage, these 255 values are divided between the two DHCP servers. For instance, if DHCP Server A has a weight of 80 and DHCP Server B has a weight of 20, then 80% of the values (204 values) will be assigned to Server A, and the remaining 20% (51 values) to Server B.
When a DHCP request is received from a client, the two DHCP servers will check if the hash value of the client falls within their respective assigned range.
- The server with the assigned range will allocate an IP address to the client.
- The server that did not allocate the IP will synchronize the lease information to avoid conflicts.
DHCP failover uses a specific protocol to manage communication and synchronization between the primary and secondary servers. This protocol handles:
- State Updates: Ensuring both servers are aware of the client’s current lease status.
- Heartbeat Mechanism: To detect when the primary or secondary server becomes unreachable.
- Failover Procedures: Automatically triggering a failover if the primary server is detected to be down.
Handling of Failover Events

The two DHCP servers periodically send heartbeat messages to ensure normal communication between them. If no response is received after three consecutive attempts, the servers consider the communication as interrupted and enter the “communications_interrupted” state. In this state, each server manages its own address pool independently.
When the servers are in the communications_interrupted state and receive a DHCP request from a client, both servers will assign different IP addresses to the client. The client will select the IP address from the first received DHCP reply and confirm it.
Once communication between the servers is restored, they will synchronize the address allocation information that occurred during the communication failure to ensure consistency.
If communication is not restored after a certain period, the remaining active DHCP server will assume that the other server has failed and gone offline. After the lease time for the address pool expires, the active server will take control of the entire address pool and will have the authority to assign addresses to clients from the full range of available IP addresses.
DHCP Failover Configuration
Section titled “DHCP Failover Configuration”| Operation | Command | Description |
|---|---|---|
| Configure DHCP failover | dhcp failover | |
| Specify the local address for DHCP server peer communication | address {A.B.C.D|Loopback0} | Define the local IP address used for communication between the DHCP servers. |
| Specify the peer address of the DHCP server | peer address <A.B.C.D> | Set the IP address of the peer DHCP server for failover communication. |
| Assign the Primary/Secondary role in DHCP failover | role {primary|secondary} | Specify the role of the DHCP server in the failover configuration, either as primary or secondary. |
| Assign HASH value weight for DHCP client allocation | split | Configure the hash value weight distribution between the two DHCP servers to manage load balancing. |
| Enable DHCP failover for a specific DHCP address pool | failover | Activate the DHCP failover function for a particular address pool to allow redundancy and load balancing. |
Configuring the Device as a DHCP Client
Section titled “Configuring the Device as a DHCP Client”Once the device is configured as a DHCP client, it can obtain an IP address and other information from the DHCP server. However, if the IP address assigned by the DHCP server to the interface falls within the same subnet as the IP address of another interface on the device, the interface will not use that IP address.
| Operation | Command | Description |
|---|---|---|
| Enter the system configuration view | configure terminal | |
| Enter the interface configuration view | interface ethernet interface vlan | |
| Enable DHCP on the interface | ip address dhcp-alloc |
DHCP Relay Configuration
Section titled “DHCP Relay Configuration”Introduction
Section titled “Introduction”Since DHCP uses broadcasting to send request messages during the IP address dynamic allocation process, it is suitable only for cases where the DHCP client and server are within the same subnet. When the DHCP server and client are not in the same subnet, the DHCP relay mechanism needs to be employed.
Explanation of Principles
Section titled “Explanation of Principles”In the context of DHCP relay, the message exchange is depicted as shown in the diagram:

1.The Client Sends DHCP Discovery Broadcast:
When a DHCP client is located within a subnet and needs to obtain an IP address and other configuration information, it broadcasts a DHCP Discovery message (DHCP Discover) to the broadcast address of the local network.
2.Relay Agent Forwards DHCP Message:
The DHCP relay agent forwards the received DHCP Discovery message (along with any other relevant DHCP messages) to the DHCP server, encapsulating the original broadcast message.
3.DHCP Server Response:
Upon receiving the forwarded DHCP Discovery message in a different subnet, the DHCP server assigns an IP address to the client and generates a DHCP Offer broadcast message (DHCP Offer) back to the relay agent.
4.Relay Agent Forwards DHCP Offer:
The DHCP relay agent forwards the DHCP Offer message back to the original subnet, encapsulating the IP address and configuration information provided by the DHCP server.
5.Client Requests and Acknowledges:
The DHCP client, upon receiving the DHCP Offer message, selects a server and sends a DHCP Request message (DHCP Request) to request the allocated IP address. This request message is also forwarded by the relay agent to the DHCP server.
6.Server Acknowledgment and Response:
Upon receiving the DHCP Request message, the DHCP server sends a DHCP Acknowledgment message (DHCP Acknowledgment) back to the relay agent. Similarly, the relay agent forwards the acknowledgment message to the subnet where the client is located.
Through this process, DHCP relay allows DHCP clients and servers located in different subnets to communicate without requiring a DHCP server to be set up on each subnet. The relay agent acts as a bridge, forwarding DHCP messages between different subnets, enabling DHCP communication to span physical network boundaries.
Adding Option82
Section titled “Adding Option82”By default, when a device receives a request message from a DHCP client and re-encapsulates it, a field called “option82” is appended to the message to record the client’s location information. The “Relay agent IP address” field is the IP address of the VLAN SVI interface where the client is located. DHCP servers that support parsing the option82 field can use the information carried within it to determine which IP address range to allocate to the client. If the DHCP server does not support parsing the option82 field, the determination can be made based on the “Relay agent IP address.”
However, in scenarios involving cluster networks, access devices are configured as distributed gateways with the same SVI interface address. In such cases, the “dhcp-agent address” command needs to be used to allocate a unique agent IP address to each device. This is done to enable DHCP servers, when sending response messages, to use this unique IP address as the destination address, allowing differentiation among different access devices.
DHCP Relay Configuration
Section titled “DHCP Relay Configuration”| Operation | Command | Description |
|---|---|---|
| Enter the system configuration view | configure terminal | |
| Create a DHCP relay instance and enter the DHCP relay view | dhcp-relay relay-name {v4|v6} | |
| Specify the VLAN to which the DHCP clients belong that require dynamic IP address allocation | down_link interface vlan vlan-id | |
| Specify the interface through which the device is connected to the DHCP server | up_link interface interface-type interface-name | |
| Specify the IP address of the DHCP server | server_ip ip-address | |
| Configure using the loopback interface as the relay agent IP | loopback_interface loopback ID | |
| Enable the option to not encapsulate the option82 field (if needed) | no_option82 | |
| Configure the relay agent IP address (if needed) | dhcp-agent address ip-address |
Configuration Example
Section titled “Configuration Example”Network requirements
- Suppose User 1 and User 3 of a company belong to Department A, User 2 and User 4 belong to Department B, Device A acts as a DHCP relay, and Device B acts as a DHCP server. It is required to assign IP addresses between 10.1.2.2 and 10.1.2.100 to Department A and between 10.1.10.2 and 10.1.10.100 to Department B.
- DNS server, gateway and other information are assigned by DHCP server.

Procedure
1.Configuration of Device A
# Create VLAN 100 and configure the IP address
sonic(config)# vlan 100sonic(config)# interface ethernet 1sonic(config-if-1)# switchport access vlan 100sonic(config)# interface ethernet 2sonic(config-if-2)# switchport access vlan 100sonic(config)# interface vlan 100sonic(config-vlanif-100)# ip address 10.1.2.1/24# Create VLAN 200 and configure the IP address
sonic(config)# vlan 200sonic(config)# interface ethernet 3sonic(config-if-3)# switchport access vlan 200sonic(config)# interface ethernet 4sonic(config-if-4)# switchport access vlan 200sonic(config)# interface vlan 200sonic(config-vlanif-200)# ip address 10.1.10.1/24# Configure the IP address
sonic(config)# interface ethernet 5sonic(config-if-5)# ip address 10.110.1.1/30sonic(config)# interface loopback 0sonic(config-if-lo0)# ip address 10.120.1.1/32Enable DHCP relay functionsonic(config)# dhcp-relay test v4sonic(config-dhcp-relay-test_v4)# down_link interface vlan 100sonic(config-dhcp-relay-test_v4)# down_link interface vlan 200sonic(config-dhcp-relay-test_v4)# up_link interface 5sonic(config-dhcp-relay-test_v4)# server_ip 10.110.1.2sonic(config-dhcp-relay-test_v4)# loopback_interface loopback 0sonic(config-dhcp-relay-test_v4)# exit2.Configuration of Device B
sonic(config)# interface ethernet 1sonic(config-if-1)# ip address 10.110.1.2/30sonic(config-if-1)# dhcp select server# Create DHCP address pool
sonic(config)# dhcp pool userAsonic(config-dhcp-pool-userA)# network 10.1.2.1 255.255.255.0sonic(config-dhcp-pool-userA)# address-pool 10.1.2.2 10.1.2.100sonic(config-dhcp-pool-userA)# dns 8.8.8.8sonic(config-dhcp-pool-userA)# exitsonic(config)# dhcp pool userBsonic(config-dhcp-pool-userB)# network 10.1.10.1 255.255.255.0sonic(config-dhcp-pool-userB)# address-pool 10.1.10.2 10.1.10.100sonic(config-dhcp-pool-userB)# dns 8.8.8.8sonic(config-dhcp-pool-userB)# exitVerify configuration
1.Check the requested IP address on the PC.
C:\Users\test>ipconfigWindows IP ConfigurationEthernet Adapters Ethernet:Connect to a specific DNS suffix . . . . . . :Local Link IPv6 Address. . . . . . . . . . . : fe80::a495:f96e:6573:c383%12IPv4 address . . . . . . . . . . . . . . . . : 10.1.10.144subnet mask . . . . . . . . . . . . . . . . .: 255.255.255.0Default Gateway. . . . . . . . . . . . . . . : 10.1.10.12.Use the commands show dhcp relay config and show dhcp pool info on Device A and Device B respectively to view the DHCP relay and DHCP server configuration.