---
title: DHCP Snooping Configuration
slug: enterprise-v5p2/dhcp-snooping-configuration
createdAt: 2025-12-02T11:12:10.897Z
---

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

DHCP Snooping monitors DHCP-REQUEST and trusted port received DHCP-ACK messages, recording DHCP Snooping entries including client MAC addresses, assigned IP addresses, VLANs, and other information.

# <font color="#1d50a2">Explanation of Principles</font>

## <font color="#1d50a2">Trusted Ports for DHCP Snooping</font>

When DHCP Snooping is enabled, devices forward DHCP client's DHCP request messages through trusted ports to legitimate DHCP servers, and the device generates Snooping Binding Table (SNP) entries based on the DHCP ACK response from the server.

DHCP Snooping categorizes ports into two security levels, and they are handled differently upon receiving DHCP messages:

- **Trusted Ports**: Trusted ports receiving DHCP ACK messages from DHCP servers generate SNP entries based on the contents of the messages.
- **Untrusted Ports**: Untrusted ports only forward DHCP ACK messages from DHCP servers and do not generate SNP entries.

## <font color="#1d50a2">DHCP Snooping Table</font>

SNP entries contain information such as VLAN, MAC, IP, INTERFACE, etc. These entries are recorded by monitoring DHCP-ACK messages received through trusted ports. The entries are removed based on DHCP Release messages received on ports with DHCP Snooping enabled. Since the DHCP Snooping binding table records the correspondence between DHCP client IP addresses and MAC addresses, this information enables the following functionalities:

- Dynamic ARP Inspection (DAI): DAI uses DHCP Snooping entries to determine the legitimacy of the user sending ARP packets, thus preventing ARP attacks from unauthorized users.
- Source Address Validation Improvement (SAVI): SAVI uses DHCP Snooping entries to validate the legitimacy of users sending ND (Neighbor Discovery) packets, preventing ND attacks from unauthorized users.
- IP Source Guard (IPSG): IPSG filters IP packets on ports dynamically obtained from the DHCP Snooping table, preventing unauthorized packets from passing through those ports.
- MAC-scan: Based on DHCP Snooping entries, a scan can be initiated on terminal devices listed in the table to detect their online status.

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

| **Configure Tasks**            | **Instructions** |
| ------------------------------ | ---------------- |
| Enable DHCP Snooping           | Required         |
| Configure port as trust  state | Required         |

## <font color="#1d50a2">Enabling DHCP Snooping Function</font>

Enabling the DHCP Snooping function requires a two-step process: first, enabling the global DHCP Snooping functionality, and then enabling DHCP Snooping for specific interfaces or VLANs.

| **Operation**                        | **Command**                                                                        | **Description** |
| ------------------------------------ | ---------------------------------------------------------------------------------- | --------------- |
| Enter the system  configuration view | **configure  terminal**                                                            |                 |
| Enable DHCP Snooping                 | **dhcp snooping  enable\{v4\|v6}**                                                 |                 |
| Enter the corresponding  view        | Interface View   **interface ethernet** *interface-id*   VLAN View   **vlan** *ID* |                 |
| Enable DHCP Snooping                 | **dhcp-snooping enable**                                                           |                 |

## <font color="#1d50a2">Configuring Ports as Trusted</font>

To ensure that the device generates SNP entries only for DHCP ACK packets received from legitimate DHCP servers, you need to set the interfaces connected directly or indirectly to trusted DHCP servers as trusted interfaces. Other interfaces should be set as untrusted interfaces. This guarantees that, after enabling the respective security features, only terminals that obtain IP addresses from legitimate DHCP servers can access the network, preventing unauthorized access from self-deployed DHCP servers.

| **Operation**                        | **Command**                                                                        | **Description** |
| ------------------------------------ | ---------------------------------------------------------------------------------- | --------------- |
| Enter the system  configuration view | **configure  terminal**                                                            |                 |
| Enter the corresponding  view        | Interface View   **interface ethernet** *interface-id*   VLAN View   **vlan** *ID* |                 |
| Configure ports as  trusted          | **dhcp-snooping trusted**                                                          |                 |

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

| **Operation**                                 | **Command**                   | **Description** |
| --------------------------------------------- | ----------------------------- | --------------- |
| Display  DHCP Snooping related configurations | **show dhcp snooping config** |                 |
| Display  DHCP Snooping table                  | **show snooping table**       |                 |

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

<font color="#1d50a2">**Network requirements**</font>

A company wants to assign IP addresses to terminals in the network through a DHCP server in order to facilitate management, and at the same time needs to prohibit users from accessing the network through statically configured IP addresses.

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/Gv8b6KArNn1d2YbRrwLAA-20251202-111449.png" size="80" width="846" height="284" position="center" showCaption="false"}

<font color="#1d50a2">**Procedure**</font>

1. Create VLAN 100 and configure the IP address

```text
sonic(config)# vlan 100
sonic(config)# interface ethernet 1
sonic(config-if-1)# switchport access vlan 100
sonic(config)# interface ethernet 2
sonic(config-if-2)# switchport access vlan 100
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ip address 10.1.2.1/24
```

2. Enable DHCP relay function

```text
sonic(config)# dhcp-relay test v4 
sonic(config-dhcp-relay-test__v4)# down_link interface vlan 100
sonic(config-dhcp-relay-test__v4)# up_link interface 5
sonic(config-dhcp-relay-test__v4)# server_ip 10.10.1.1
sonic(config-dhcp-relay-test__v4)# loopback_interface loopback 0
sonic(config-dhcp-relay-test__v4)# exit
```

3. Enabling DHCP Snooping

```text
sonic(config)# dhcp snooping enable
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# dhcp-snooping enable
```

4. Configure the interface to which the DHCP Server is connected as a trusted port

```text
sonic(config)# interface ethernet 5
sonic(config-if-5)# dhcp-snooping enable
sonic(config-if-5)# dhcp-snooping trusted
```

5. Enables DAI and IPSG to check the legitimacy of user messages

```text
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ipv4-source-check enable
sonic(config-vlanif-100)# arp anti-attack-check enable
```

<font color="#1d50a2">**Verify configuration**</font>

1. Check the obtained IP address on the user's PC.
2. Modify the IP address on the user's PC to a static configuration, ping the external network address and the PC's gateway address, respectively, The ping operation Failed.
3. View the packet loss statistics of the security features on the device.

```text
sonic# show user-bind counter 
Interface   Drop Packets
----------- --------------
Vlan100        4028
```

##

