---
title: DHCP Relay Configuration
slug: enterprise-v6p1/hTJO-dhcp-relay-configuration
createdAt: 2025-12-04T06:55:07.575Z
---

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

### <font color="#1d50a2">show dhcp relay config</font>

**\[Command]**
**show dhcp relay config**

**\[Purpose]**
Display DHCP relay related configuration

**\[View]**
System view

**\[Use Cases]**

```plaintext
sonic# show dhcp relay config
+-----------+-----------+-------------------+-----------+---------------------+
| Name      | down link | up link           | loopback  | server              |
+===========+===========+===================+===========+=====================+
| test1(v4) |Vlan800    | Ethernet49        | Loopback0 | 150.1.0.1,151.1.0.1 |
+-----------+-----------+-------------------+-----------+---------------------+
| test2(v6) |Vlan800    | Ethernet49        | Loopback0 | 4005::1             |
+-----------+-----------+-------------------+-----------+---------------------+
```

### <font color="#1d50a2">dhcp-relay \{v4|v6\}</font>

**\[Command]**
**dhcp-relay** *name* **\{v4|v6}**
**no dhcp-relay** *name* **\{v4|v6}**

**\[Purpose]**
Configuring DHCP relay instance

**\[Parameter]**

| **Parameter** | **Description** |
| ------------- | --------------- |
| *name*        | DHCP Relay name |

**\[View]**
System configuration view

**\[Usage Scenario]**
When users and DHCP servers are in different broadcast domains (different subnets), the device can act as a DHCP relay agent to encapsulate the user's DHCP request broadcast message into a unicast message and send it to the DHCP server.

**\[Comment]**
The device supports the configuration of multiple DHCP instances as DHCP relay for the scenario that different terminals use different DHCP Server.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test__v4)#
```

### <font color="#1d50a2">down\_link interface vlan</font>

**\[Command]**
**down\_link interface vlan** *vlan\_id*
**no down\_link interface vlan** *vlan\_id*

**\[Purpose]**
Specify the interface ID of the connected terminal in the relay instance

**\[Parameter]**

| **Parameter** | **Description**                                                 |
| ------------- | --------------------------------------------------------------- |
| *vlan\_id*    | VLAN ID of the physical port to which the terminal is connected |

**\[View]**
DHCP-relay view

**\[Usage Scenario]**
To allow users who need to obtain IP addresses dynamically, specify the VLAN where these users are located as the downstream interface of the Relay instance. All users within this VLAN can then obtain IP addresses from the DHCP server configured within this instance.

**\[Note]**
Multiple VLAN interfaces can be configured under the same instance.
The VLAN bound to the DHCP Relay instance requires an IP address to be configured.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test__v4)# down_link interface vlan 10
```

### <font color="#1d50a2">up\_link interface</font>

**\[Command]**
**up\_link interface \{** *interface\_type* **} \{** *interface\_name* **}**
**no up\_link interface \{** *interface\_type* **} \{** *interface\_name* **}**

**\[Purpose]**
Specify the interface ID of the Relay instance to which the DHCP server is connected

**\[Parameter]**

| **Parameter**     | **Description**                                            |
| ----------------- | ---------------------------------------------------------- |
| *interface\_type* | Supported configurations\:ethernet, link-aggregation, vlan |
| *interface\_name* | Supported configurations: ethernet\_num, lag\_id, vlan\_id |

**\[View]**
DHCP-relay view

**\[Usage Scenario]**
In a DHCP relay environment, to ensure that only legitimate DHCP response packets from a specified interface are accepted, you can use this command to specify the interface. This prevents illegal servers from providing unauthorized IP addresses to users, thereby maintaining network security.

**\[Comment]**
Multiple interfaces are supported to be configured under the same instance.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test__v4)# up_link interface ethernet 1
```

### <font color="#1d50a2">server\_ip</font>

**\[Command]**
**server\_ip \{** *A.B.C.D* **|** *A\:B:C\:D:E\:F:G*:H **}**
**no server\_ip \{** *A.B.C.D* **|** *A\:B:C\:D:E\:F:G*:H **}**

**\[Purpose]**
Specify the DHCP server IP address of the relay instance

**\[Parameter]**

| **Parameter**        | **Description** |
| -------------------- | --------------- |
| *A.B.C.D*            | ipv4 address    |
| *A\:B:C\:D:E\:F:G*:H | ipv6 address    |

**\[Note]**
Multiple DHCP server IP addresses can be configured under the same instance.
DHCP servers under different instances can be distinct.
The relay sends DHCP request packets to all DHCP servers and forwards all received response packets to the client for selection.

**\[View]**
DHCP-relay view

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test __v4)# server_ip 150.1.0.1
```

### <font color="#1d50a2">loopback\_interface loopback</font>

**\[Command]**
**loopback\_interface loopback** *loopback\_id*
**no loopback\_interface loopback** *loopback\_id*

**\[Purpose]**
To configure the DHCP relay packet's relay agent address as the IP address of a Loopback interface

**\[View]**
DHCP-relay view

**\[Usage Scenario]**
In scenarios where users utilize a distributed gateway, if the DHCP relay still uses the user gateway's IP address as the Relay Agent IP address, the DHCP server will be unable to communicate with the relay through that IP address, resulting in unreachable response packets. Users can use this command to specify the Relay Agent IP address as the IP address of a Loopback interface that uniquely identifies a device. This allows the DHCP server to forward response packets to the requesting DHCP relay.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test __v4)# loopback_interface loopback 0
```

### <font color="#1d50a2">dhcp-agent address</font>

**\[Command]**
**dhcp-agent address** *A.B.C.D*

**\[Purpose]**
Specify the DHCP Server IP address of the Relay instance

**\[View]**
Interface vlan view

**\[Usage Scenario]**
By default, DHCP relays insert the option82 field into DHCP request packets, populating the DHCP relay interface's IP address with the "link-selection" field within option82. DHCP servers use this field to select an IP address pool for allocation. However, some DHCP servers do not support parsing the "link-selection" field. In such cases, you need to configure this command to specify the Relay Agent IP so that the server can select an IP address pool based on this field.

**\[Note]**
When used in a distributed gateway scenario, different relay devices should be configured with different IP addresses to ensure that the DHCP server can forward response packets to the originating DHCP relay.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# dhcp-agent address 192.168.1.10
```

### <font color="#1d50a2">no\_option82</font>

**\[Command]**
**no\_option82**
**no no\_option82**

**\[Purpose]**
Enable no option82 mode

**\[View]**
DHCP-relay view

**\[Comment]**
After configuring this command, DHCP relay will no longer include the option82 field in forwarded DHCP packets. This command should be used in conjunction with the **dhcp-agent address** command.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test __v4)# no_option82
```

### <font color="#1d50a2">dhcp option82 encapsulation remote-id</font>

**\[Command]**
**dhcp option82 encapsulation remote-id** *value*

**\[Purpose]**
Configuring the addition of the “remote-id” sub-option in option82

**\[View]**
interface vlan view

**\[Usage Scenario]**
To configure the addition of the "remote-id" sub-option in Option 82, you may need to specify the relevant settings based on your networking equipment or DHCP server software. In general, Option 82 is often associated with DHCP and is used to carry additional information about the client.

**\[Use Cases]**

```plaintext
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# dhcp option encapsulation remote-id clientUser
```

### <font color="#1d50a2">source\_ip</font>

**\[Command]**
**source\_ip** *A.B.C.D*
**no source\_ip**

**\[Purpose]**
Specify the source IP for DHCP message interactions.

**\[View]**
DHCP-relay view

**\[Usage Scenario]**
This command allows you to specify the Ethernet layer source IP address for DHCP relay messages.

**\[Use Cases]**

```plaintext
sonic# configure terminal
sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test1__v4)# source_ip 30.102.0.216
```

##

