Skip to content
Ask AI

DHCP Configuration Guide

Dynamic Host Configuration Protocol (DHCP) is a technology used for centralized dynamic management and configuration of user IP addresses. DHCP belongs to the TCP/IP protocol, defined by RFC 2131, and adopts a client/server communication mode. The client (DHCP Client) submits a configuration request to the server (DHCP Server), and the server returns the configuration information assigned to the client. It is usually applied in large local area network environments, mainly for centralized management and allocation of IP addresses, enabling hosts in the network environment to dynamically obtain information such as IP addresses, Gateway addresses, DNS server addresses, etc., and can improve address utilization. However, users do not need to equip a DHCP server on every network. When the DHCP client and DHCP server are not in the same network segment, DHCP Relay can be configured on the corresponding device to forward DHCP messages between the DHCP server and DHCP client, helping clients without IP addresses to obtain IP across network segments while avoiding the problem of too many DHCP servers.

The DHCP server is mainly responsible for selecting idle IP addresses from the IP address pool to allocate to DHCP clients, and can also provide network parameters for DHCP clients, such as gateway addresses, TFTP server addresses, etc. Ability to manage IP address leases, track and manage IP address lease terms, avoid address conflicts, and promptly recover and reassign IP addresses released by DHCP clients.

DHCP clients mainly send DHCP requests to the network, obtaining information such as IP addresses and network parameters through the DHCP protocol.

DHCP relay is mainly responsible for forwarding DHCP messages between DHCP servers and DHCP clients, assisting DHCP servers in dynamically allocating network parameters to DHCP clients, and realizing the forwarding of DHCP messages in different network segments.

An address pool is a collection of all IP addresses that DHCP servers can allocate to clients. In addition to IP addresses, the address pool can also be configured with network parameters such as lease term, subnet mask, default gateway, etc.

When the DHCP server assigns an IP address to a client, it also sets a usage period for the client, which is the lease term. Before the lease term expires, if the client still needs to continue using this IP address, it will initiate a renewal request to renew the lease. If it is no longer needed, it will actively release the IP address after reaching the lease term. The DHCP server will retrieve the IP address released by the client and put it back into the address pool for reuse.

Currently, it supports assigning specific IP addresses and network parameters based on certain user information. User class is to create matching conditions, match this type of user information, binds the address pool after matching, and allocate IP addresses. Currently, it only supports matching the remote ID and circuit ID of option 82, as well as option 93, which is the system architecture information of the client. The option group is to assign specific network parameters to users matched on the user class.

The option in DHCP messages is used to transmit control information and network configuration parameters, enabling dynamic address allocation while providing clients with richer network configuration information. The range of DHCP Options is 1-255, and common DHCP options are shown in the following table:

Table 1 DHCP Options

Option IDOption Content
1Subnet Mask
3Gateway address
6DNS server address
43Manufacturer customization
50IP address options requested by the client
51Lease time
53DHCP message type
55Request a list of options. The client uses this option to indicate which network configuration parameters need to be obtained from the server. The content of this option is the option value corresponding to the parameter requested by the client
60Manufacturer identification, the client uses this option to identify the manufacturer to which they belong
61Client Identifier
66TFTP server
67Bootfile
82DHCP relay info

We will introduce the process of obtaining an IP address for a DHCP client for the first time in both scenarios without and with DHCP relay.

When the DHCP client and DHCP server are in the same network segment, DHCP packets do not need to be forwarded through DHCP relays.

  1. When a DHCP client first joins the network, it sends a DHCP Discover broadcast message to all devices in the network, searching for available DHCP server information.
  2. After receiving the DHCP address request from the client, the DHCP server selects an unallocated IP from the IP address pool and sends a DHCP OFFER packet to the DHCP client. The OFFER packet contains IP address, lease information, server information, and other content.
  3. After receiving the OFFER packet, the DHCP client sends a REQ broadcast packet to the DHCP server. The REQ packet contains information about the DHCP server and the IP address to be assigned, formally requesting the assigned IP address from the server. If there are multiple DHCP servers and DHCP clients responding to DHCP OFFER messages, the DHCP client generally only receives the first DHCP OFFER message received.
  4. After receiving the REQ message, the DHCP server determines whether the DHCP server information in the REQ message is its own. If it is not, it discards the message. If it is, it sends an ACK confirmation message to the client to obtain the IP address.

When the DHCP client and DHCP server are in different network segments, DHCP packets need to be forwarded through DHCP relays.

  1. When a DHCP client first joins the network, it sends a DHCP Discover broadcast message requesting an IP address.
  2. After receiving the Discover request message initiated by the client, the DHCP relay changes the destination IP address in the message to the address of the DHCP server, changes the source address of the message to the address of the DHCP relay, and then sends the DHCP Discover message to the server in unicast form.
  3. After receiving the DHCP Discover message, the DHCP server assigns parameters such as IP address to the client and then sends a DHCP OFFER message to the DHCP relay unicast.
  4. After receiving the OFFER message sent by the server, the DHCP relay will forward it to the DHCP client.
  5. After receiving the OFFER message, the DHCP client will send the DHCP REQ message to the DHCP relay in broadcast form. After receiving the REQ message, the DHCP relay will also forward it to the DHCP server in unicast form.
  6. After receiving the REQ message, the DHCP server replies with an ACK message to the DHCP relay, and the relay device forwards it to the DHCP client.
  7. After receiving the ACK confirmation message, the DHCP client obtains the IP address.

Table 2 DHCP Default Setting

ParameterDefault value
DHCPDisable
Deafult lease time600s
Max lease time7200s
giaddr addressDownlink VLAN IP

Before configuring a DHCP server or DHCP relay, the DHCP feature needs to be enabled first.

Table 3 Enable DHCP feature

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Enable DHCP functionfeature dhcp state enable-

Table 4 Configure Enable DHCP server function

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter Ethernet interface or VLANIF configuration viewinterface [ethernet interface-name|vlan vlan-id]-
Enable the DHCP Server function of the interfacedhcp server-

Table 5 Configure address pool

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create DHCP Server address pool and enter DHCP pool configuration viewdhcp pool name-
Configure the network segment of the address poolnetwork A.B.C.D/M-
Configure address pool IP rangeaddress-pool start_ip end_ipThe end_ip needs to be after the start_ip

Table 6 Configure options

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Enter DHCP pool configuration viewdhcp pool name-
Configure lease timelease-time default_time max_time-
Configure bootfile optionbootfile name-
Configure DNS Optiondns A.B.C.D-
Configure next server Optionnext-server A.B.C.D-
Configure tftp server Optiontftp-server A.B.C.D-
Configure capwap-ac Optioncapwap-ac A.B.C.D-
Configure routers Optionrouters A.B.C.D-
Configure option43option43 hex value force-

Table 7 Configure address allocation strategy

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create DHCP Server user class and enter DHCP user class configuration viewdhcp class name-
Create a DHCP Server option group and enter the option group configuration viewdhcp option-group id-
Create user class matching rulesif-match rule rule_id option option_idOnly support option82 and option93
Configure user class address rangeclass name address-pool start_ip end_ip-
Bind user classes and option groupsclass name option-group id-

Table 8 Configure DHCP server failover

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Enable DHCP Server dual machine hot standbydhcp failover name-
Configure local IP addressaddress {A.B.C.D|loopback 0}-
Configure peer IP addresspeer address A.B.C.D-
Configure peer offline timeauto-partner-down time-
Configure maximum communication interruption timemax-response-delay time-
Configure primary and secondary rolesrole {primary|secondary}-

Table 9 Configure DHCP relay

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create DHCP relay and enter configuration view.dhcp-relay name v4-
Configure DHCP relay downlink VLAN.downlink vlan vlan_idThe downlink is the port connected to the client
Configure DHCP relay uplink.uplink {ethernet|link-aggregation|vlan} interface-nameThe uplink is the port connected to the server
Configure DHCP server address.server {A.B.C.D}-

Giaddd (Gateway IP Address) is a field in the DHCP protocol primarily used to identify the IP address of a relay agent. By default, the giaddr address is the IP address of the downstream VLAN. When the DHCP server receives a DHCP packet, it will allocate an IP address to the client from the correct address pool based on the network segment where the giaddr address is located.

Table 10 Configure giaddr

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create DHCP relay and enter configuration view.dhcp-relay name v4-
Configure giaddr.downlink vlan vlan_id giaddr A.B.C.D-

Option82 sub5 is a sub option of the relay agent information option in DHCP packets, which is a link selection sub item. When assigning IP addresses to DHCP clients, the DHCP server can allocate IP addresses in the same network segment as the address based on this IP address, which helps to achieve more accurate address allocation strategies. When there are multiple IP addresses in the current VLAN, option82_stub5 can be manually configured to be one of the IP addresses in the specified network segment, thereby controlling the client to obtain the IP address of the specified network segment. After configuring option82_stub5, the DHCP server will allocate an IP based on the option82_stub5 address network segment and search for a route to the relay based on giaddr.

Table 11 Configure option82

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Create DHCP relay and enter configuration viewdhcp-relay name v4-
Configure the sub5 address of option85downlink vlan vlan_id option82_sub5 A.B.C.D-

Table 12 DHCP Display and Maintenance

PurposeCommandsDescription
Display the address pool information of DHCP serversshow dhcp pool info ip-version v4-
Display the addresses allocated by the DHCP servershow dhcp pool ip-in-use ip-version v4-
Display DHCP server reclaimed addressesshow dhcp pool expired ip-version v4-
Display DHCP server user class configurationshow dhcp class-
Display DHCP Server Options Group Configurationshow dhcp option-group-
Display DHCP relay configuration informationshow dhcp_relay-
  1. Networking Requirements An efficient IP address management mechanism is needed within a certain enterprise to enable all internal terminals to dynamically obtain valid IP addresses, while avoiding IP conflicts and address waste. DHCP servers need to be configured to automatically allocate IP addresses, reducing the workload of manual configuration and improving the automation level of network management.
  2. Topology

  1. Configuration steps

#Enable the interface DHCP server function on the DHCP server.

sonic# configure
sonic(config)# interface ethernet 0/88
sonic(config-if-0/88)# dhcp server
sonic(config-if-0/88)# exit

#Configure interface IP address

sonic# configure
sonic(config)# interface ethernet 0/88
sonic(config-if-0/88)# ip address 10.0.0.1/24
sonic(config-if-0/88)# exit

#Create DHCP address pool, configure address pool IP information, configure network segment and other network parameter information

sonic# configure
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-test1)# network 10.0.0.1/24
sonic(config-dhcp-pool-test1)# address-pool 10.0.0.10 10.0.0.200
sonic(config-dhcp-pool-test1)# lease-time 1200 2000
  1. Verify configuration

#show dhcp server configuration

sonic# show dhcp pool info
--------------------------------------------------
Pool-name : test1
Network : 10.0.0.0
Mask : 255.255.255.0
Lease : 10.0.0.10 - 10.0.0.200
Lease_default_time : 600
Lease_max_time : 7200

After each PC goes online, it will initiate an IP address request and successfully obtain the IP address of the 10.0.0.0/24 network segment.

  1. Networking Requirements A large enterprise has multiple office areas and departments, each located in a different subnet. To simplify network management, the enterprise has decided to deploy a DHCP server in the core network and ensure that clients in each subnet can successfully obtain IP addresses through DHCP relays.
  2. Topology

  1. Different subnets require different address pool information to be configured on the DHCP server. Taking one subnet configuration as an example, the configuration steps are as follows.

A. Configure DHCP server information.

#Enable the DHCP server interface function on the DHCP server device and configure the interface IP address

sonic# configure
sonic(config)# interface ethernet 0/88
sonic(config-if-0/88)# dhcp server
sonic(config-if-0/88)# ip address 100.0.0.1/24

#Configure static routing to make the IP address assigned by the server reachable to the relay

sonic# configure
sonic(config)# ip route 10.0.0.2/24 100.0.0.2

#Create DHCP address pool and configure network parameter information

sonic# configure
sonic(config)# dhcp pool test1
sonic(config-dhcp-pool-test1)# network 10.0.0.1/24
sonic(config-dhcp-pool-test1)# address-pool 10.0.0.10 10.0.0.200
sonic(config-dhcp-pool-test1)# lease-time 600 1000
sonic(config-dhcp-pool-test1)# exit

B. Configure DHCP relay.

#Configure the IP address for the interface connected to the server

sonic# configure
sonic(config)# interface ethernet 0/60
sonic(config-if-0/60)# ip address 100.0.0.2/24

#Create a downstream VLAN and configure an IP address in the same network segment as the subnet

sonic# configure
sonic(config)# vlan 100
sonic(config-vlan-100)# exit
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ip address 10.0.0.2/24
sonic(config-vlanif-100)# exit

#Create DHCP relay and configure relay information

sonic# configure
sonic(config)# dhcp-relay t1 v4
sonic(config-dhcp-relay-t1)# downlink vlan 100
sonic(config-dhcp-relay-t1)# uplink ethernet 0/60
sonic(config-dhcp-relay-t1)# server 100.0.0.1
sonic(config-dhcp-relay-t1)# exit
  1. Verify configuration

#show DHCP relay configuration

sonic# show dhcp_relay
+------------+-------------+------------+------------+-----------+-------+
| Name | down link | up link | loopback | server | vrf |
+============+=============+============+============+===========+=======+
| t1__v4(v4) | vlan100 | 0/60 | NA | 100.0.0.1 | NA |
+------------+-------------+------------+------------+-----------+-------+

When a PC device in the 10.0.0.0/24 network segment goes online, it will automatically obtain an IP address.