---
title: DHCP Configuration Guide
slug: aidc/dhcp-configuration-guide
description: IP Service Configuration Guide
createdAt: 2025-11-12T12:13:55.454Z
---

## <font color="#1d50a2">Introduction</font>

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.

## <font color="#1d50a2"> Concepts</font>

### <font color="#1d50a2">DHCP server</font>

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.

### <font color="#1d50a2">DHCP client</font>

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

### <font color="#1d50a2">DHCP relay</font>

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.

### <font color="#1d50a2">Address pool</font>

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.

### <font color="#1d50a2">Lease time</font>

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.

### <font color="#1d50a2">Class and option-group</font>

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.

### <font color="#1d50a2">DHCP option</font>

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:

<font color="#1d05a2">Table 1 DHCP Options</font>

| **Option ID** | **Option Content**                                                                                                                                                                                                                                   |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1             | Subnet Mask                                                                                                                                                                                                                                          |
| 3             | Gateway address                                                                                                                                                                                                                                      |
| 6             | DNS server address                                                                                                                                                                                                                                   |
| 43            | Manufacturer customization                                                                                                                                                                                                                           |
| 50            | IP address options requested by the client                                                                                                                                                                                                           |
| 51            | Lease time                                                                                                                                                                                                                                           |
| 53            | DHCP message type                                                                                                                                                                                                                                    |
| 55            | Request 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 |
| 60            | Manufacturer identification, the client uses this option to identify the manufacturer to which they belong                                                                                                                                           |
| 61            | Client Identifier                                                                                                                                                                                                                                    |
| 66            | TFTP server                                                                                                                                                                                                                                          |
| 67            | Bootfile                                                                                                                                                                                                                                             |
| 82            | DHCP relay info                                                                                                                                                                                                                                      |

## <font color="#1d50a2">Basic Principle</font>

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.

### <font color="#1d50a2">No DHCP Relay scene</font>

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.

### <font color="#1d50a2">DHCP relay scene</font>

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.

## <font color="#1d50a2">DHCP Configuration</font>

### <font color="#1d50a2">DHCP Default Setting</font>

<font color="#1d05a2">Table 2 DHCP Default Setting</font>

| **Parameter**      | **Default value** |
| ------------------ | ----------------- |
| DHCP               | Disable           |
| Deafult lease time | 600s              |
| Max lease time     | 7200s             |
| giaddr address     | Downlink VLAN IP  |

### <font color="#1d50a2">Enable DHCP feature</font>

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

<font color="#1d05a2">Table 3 Enable DHCP feature</font>

| **Purpose**                      | **Commands**                  | **Description** |
| -------------------------------- | ----------------------------- | --------------- |
| Enter global configuration view. | **configure terminal**        | -               |
| Enable DHCP function             | **feature dhcp state enable** | -               |

### <font color="#1d50a2">Configure the device as a DHCP server</font>

### <font color="#1d50a2">Enable DHCP server function</font>

<font color="#1d05a2">Table 4 Configure Enable DHCP server function</font>

| **Purpose**                                           | **Commands**                                                       | **Description** |
| ----------------------------------------------------- | ------------------------------------------------------------------ | --------------- |
| Enter global configuration view                       | **configure terminal**                                             | -               |
| Enter Ethernet interface or VLANIF configuration view | **interface** \[**ethernet** *interface-name*\|**vlan** *vlan-id*] | -               |
| Enable the DHCP Server function of the interface      | **dhcp server**                                                    | -               |

### <font color="#1d50a2">Configure address pool</font>

<font color="#1d05a2">Table 5 Configure address pool</font>

| **Purpose**                                                            | **Commands**                         | **Description**                                 |
| ---------------------------------------------------------------------- | ------------------------------------ | ----------------------------------------------- |
| Enter global configuration view.                                       | **configure terminal**               | -                                               |
| Create DHCP Server address pool and enter DHCP pool configuration view | **dhcp pool** *name*                 | -                                               |
| Configure the network segment of the address pool                      | **network** *A.B.C.D/M*              | -                                               |
| Configure address pool IP range                                        | **address-pool** *start\_ip end\_ip* | The *end\_ip* needs to be after the *start\_ip* |

### <font color="#1d50a2">Configure options</font>

<font color="#1d05a2">Table 6 Configure options</font>

| **Purpose**                        | **Commands**                             | **Description** |
| ---------------------------------- | ---------------------------------------- | --------------- |
| Enter global configuration view.   | **configure terminal**                   | -               |
| Enter DHCP pool configuration view | **dhcp pool** *name*                     | -               |
| Configure lease time               | **lease-time** *default\_time max\_time* | -               |
| Configure bootfile option          | **bootfile** *name*                      | -               |
| Configure DNS Option               | **dns** *A.B.C.D*                        | -               |
| Configure next server Option       | **next-server** *A.B.C.D*                | -               |
| Configure tftp server Option       | **tftp-server** *A.B.C.D*                | -               |
| Configure capwap-ac Option         | **capwap-ac** A.B.C.D                    | -               |
| Configure routers Option           | **routers** *A.B.C.D*                    | -               |
| Configure option43                 | **option43 hex** *value* **force**       | -               |

### <font color="#1d50a2">Configure address allocation strategy</font>

<font color="#1d05a2">Table 7 Configure address allocation strategy</font>

| **Purpose**                                                                     | **Commands**                                          | **Description**                    |
| ------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------------- |
| Enter global configuration view.                                                | **configure terminal**                                | -                                  |
| Create DHCP Server user class and enter DHCP user class configuration view      | **dhcp class** *name*                                 | -                                  |
| Create a DHCP Server option group and enter the option group configuration view | **dhcp option-group** *id*                            | -                                  |
| Create user class matching rules                                                | **if-match rule** *rule\_id* **option** *option\_id*  | Only support option82 and option93 |
| Configure user class address range                                              | **class** *name* **address-pool** *start\_ip end\_ip* | -                                  |
| Bind user classes and option groups                                             | **class** *name* **option-group** *id*                | -                                  |

### <font color="#1d50a2">Configure DHCP server failover</font>

<font color="#1d05a2">Table 8 Configure DHCP server failover</font>

| **Purpose**                                       | **Commands**                             | **Description** |
| ------------------------------------------------- | ---------------------------------------- | --------------- |
| Enter global configuration view.                  | **configure terminal**                   | -               |
| Enable DHCP Server dual machine hot standby       | **dhcp failover** *name*                 | -               |
| Configure local IP address                        | **address** \{*A.B.C.D*\|**loopback 0**} | -               |
| Configure peer IP address                         | **peer address** *A.B.C.D*               | -               |
| Configure peer offline time                       | **auto-partner-down** *time*             | -               |
| Configure maximum communication interruption time | **max-response-delay** *time*            | -               |
| Configure primary and secondary roles             | **role** \{**primary**\|**secondary**}   | -               |

### <font color="#1d50a2">Configure the device as a DHCP relay</font>

### <font color="#1d50a2">Configure DHCP relay</font>

<font color="#1d05a2">Table 9 Configure DHCP relay</font>

| **Purpose**                                     | **Commands**                                                                | **Description**                                  |
| ----------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------ |
| 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\_id*                                                | The downlink is the port connected to the client |
| Configure DHCP relay uplink.                    | **uplink** \{**ethernet**\|**link-aggregation**\|**vlan**} *interface-name* | The uplink is the port connected to the server   |
| Configure DHCP server address.                  | **server** \{*A.B.C.D*}                                                     | -                                                |

### <font color="#1d50a2">Configure giaddr</font>

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.

<font color="#1d05a2">Table 10 Configure giaddr</font>

| **Purpose**                                     | **Commands**                                      | **Description** |
| ----------------------------------------------- | ------------------------------------------------- | --------------- |
| 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* | -               |

### <font color="#1d50a2">Configure option82</font>

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.

<font color="#1d05a2">Table 11 Configure option82</font>

| **Purpose**                                    | **Commands**                                              | **Description** |
| ---------------------------------------------- | --------------------------------------------------------- | --------------- |
| Enter global configuration view.               | **configure terminal**                                    | -               |
| Create DHCP relay and enter configuration view | **dhcp-relay** *name* **v4**                              | -               |
| Configure the sub5 address of option85         | **downlink vlan** *vlan\_id* **option82\_sub5** *A.B.C.D* | -               |

## <font color="#1d50a2">Display and Maintenance</font>

<font color="#1d05a2">Table 12 DHCP Display and Maintenance</font>

| **Purpose**                                          | **Commands**                               | **Description** |
| ---------------------------------------------------- | ------------------------------------------ | --------------- |
| Display the address pool information of DHCP servers | **show dhcp pool info ip-version v4**      | -               |
| Display the addresses allocated by the DHCP server   | **show dhcp pool ip-in-use ip-version v4** | -               |
| Display DHCP server reclaimed addresses              | **show dhcp pool expired ip-version v4**   | -               |
| Display DHCP server user class configuration         | **show dhcp class**                        | -               |
| Display DHCP Server Options Group Configuration      | **show dhcp option-group**                 | -               |
| Display DHCP relay configuration information         | **show dhcp\_relay**                       | -               |

## <font color="#1d50a2">Typical Configuration Example</font>

### <font color="#1d50a2">Configure the device as a DHCP server</font>

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

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/Cp1RFKdmhxg5c7vcS9hHT-20251127-064757.png" size="50" width="330" height="228" darkWidth="330" darkHeight="228" position="center" caption="Figure 1 DHCP server topology" showCaption="true"}

3. Configuration steps

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

```plaintext
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

```plaintext
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

```plaintext
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
```

4. Verify configuration

\#show dhcp server configuration

```plaintext
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.

### <font color="#1d50a2">Configure the device as a DHCP relay</font>

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

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/R0tETc3DV8FOVq54HbeNU-20251127-064854.png" size="50" width="325" height="231" position="center" caption="Figure 5 DHCP relay topology" darkWidth="325" darkHeight="231" showCaption="true"}

3. 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

```plaintext
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

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

\#Create DHCP address pool and configure network parameter information

```plaintext
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

```plaintext
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

```plaintext
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

```plaintext
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
sonicconfig-dhcp-relay-t1)# server 100.0.0.1
sonic(config-dhcp-relay-t1)# exit
```

4. Verify configuration

\#show DHCP relay configuration

```plaintext
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.

