As shown in Figure 1, SwitchA and SwitchB are Layer 2 switches, and SwitchC is the gateway that functions as a DHCP relay agent to forward DHCP messages to the DHCP server, so that DHCP clients can obtain IP addresses and related configurations from the DHCP server.
A network may encounter the following DHCP-based attacks:
To prevent DHCP-based attacks and provide high-quality service for DHCP users, configure DHCP snooping attack defense.
The configuration roadmap is as follows:
The configurations involved in this example are performed on SwitchC. This example does not provide detailed configurations for the DHCP server.
# Configure the DHCP function on the DHCP relay agent.
<HUAWEI> system-view [HUAWEI] sysname SwitchC [SwitchC] dhcp server group dhcpgroup1 [SwitchC-dhcp-server-group-dhcpgroup1] dhcp-server 10.2.1.2 [SwitchC-dhcp-server-group-dhcpgroup1] quit [SwitchC] vlan batch 10 100 [SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] port link-type access [SwitchC-GigabitEthernet0/0/1] port default vlan 10 [SwitchC-GigabitEthernet0/0/1] quit [SwitchC] interface gigabitethernet 0/0/2 [SwitchC-GigabitEthernet0/0/2] port link-type access [SwitchC-GigabitEthernet0/0/2] port default vlan 10 [SwitchC-GigabitEthernet0/0/2] quit [SwitchC] interface gigabitethernet 0/0/3 [SwitchC-GigabitEthernet0/0/3] port link-type access [SwitchC-GigabitEthernet0/0/3] port default vlan 100 [SwitchC-GigabitEthernet0/0/3] quit [SwitchC] dhcp enable [SwitchC] interface vlanif 10 [SwitchC-Vlanif10] ip address 192.168.1.1 255.255.255.0 [SwitchC-Vlanif10] dhcp select relay [SwitchC-Vlanif10] dhcp relay server-select dhcpgroup1 [SwitchC-Vlanif10] quit [SwitchC] interface vlanif 100 [SwitchC-Vlanif100] ip address 10.1.1.2 255.255.255.0 [SwitchC-Vlanif100] quit [SwitchC] ip route-static 0.0.0.0 0.0.0.0 10.1.1.1
# Assign IP address 10.2.1.2/24 to the DHCP server, configure the address pool 192.168.1.0/24, and set the gateway address of the address pool to 192.168.1.1.
# Enable DHCP snooping globally and configure the device to process only DHCPv4 messages.
[SwitchC] dhcp snooping enable ipv4
# Enable DHCP snooping on the user-side interface. GE0/0/1 is used as an example. The configuration on GE0/0/2 is the same as the configuration on GE0/0/1 and is not mentioned here.
[SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] dhcp snooping enable [SwitchC-GigabitEthernet0/0/1] quit
# Enable association between ARP and DHCP snooping.
[SwitchC] arp dhcp-snooping-detect enable
# Enable the device to check whether the GIADDR field in a DHCP Request message is 0. GE0/0/1 is used as an example. The configuration on GE0/0/2 is the same as that on GE0/0/1 and is not mentioned here.
[SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] dhcp snooping check dhcp-giaddr enable [SwitchC-GigabitEthernet0/0/1] quit
# Set the maximum rate of sending DHCP messages to the processing unit to 90 pps.
[SwitchC] dhcp snooping check dhcp-rate enable [SwitchC] dhcp snooping check dhcp-rate 90
# Enable the trap function for the rate limit and set the alarm threshold.
[SwitchC] dhcp snooping alarm dhcp-rate enable [SwitchC] dhcp snooping alarm dhcp-rate threshold 500
# Configure the user-side interface. GE0/0/1 is used as an example. The configuration on GE0/0/2 is the same as that on GE0/0/1 and is not mentioned here.
[SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] dhcp snooping check dhcp-request enable [SwitchC-GigabitEthernet0/0/1] dhcp snooping alarm dhcp-request enable [SwitchC-GigabitEthernet0/0/1] dhcp snooping alarm dhcp-request threshold 120 [SwitchC-GigabitEthernet0/0/1] quit
# Configure the user-side interface. GE0/0/1 is used as an example. The configuration on GE0/0/2 is the same as that on GE0/0/1 and is not mentioned here.
[SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] dhcp snooping max-user-number 20 [SwitchC-GigabitEthernet0/0/1] dhcp snooping check dhcp-chaddr enable [SwitchC-GigabitEthernet0/0/1] dhcp snooping alarm dhcp-chaddr enable [SwitchC-GigabitEthernet0/0/1] dhcp snooping alarm dhcp-chaddr threshold 120 [SwitchC-GigabitEthernet0/0/1] quit
# Run the display dhcp snooping configuration command to view the DHCP snooping configuration.
[SwitchC] display dhcp snooping configuration # dhcp snooping enable ipv4 dhcp snooping check dhcp-rate enable dhcp snooping check dhcp-rate 90 dhcp snooping alarm dhcp-rate enable dhcp snooping alarm dhcp-rate threshold 500 arp dhcp-snooping-detect enable # interface GigabitEthernet0/0/1 dhcp snooping enable dhcp snooping check dhcp-giaddr enable dhcp snooping check dhcp-request enable dhcp snooping alarm dhcp-request enable dhcp snooping alarm dhcp-request threshold 120 dhcp snooping check dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr threshold 120 dhcp snooping max-user-number 20 # interface GigabitEthernet0/0/2 dhcp snooping enable dhcp snooping check dhcp-giaddr enable dhcp snooping check dhcp-request enable dhcp snooping alarm dhcp-request enable dhcp snooping alarm dhcp-request threshold 120 dhcp snooping check dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr threshold 120 dhcp snooping max-user-number 20 #
# Run the display dhcp snooping interface command to view DHCP snooping information on an interface. The values of Check dhcp-giaddr, Check dhcp-chaddr, and Check dhcp-request fields are Enable. Take the display on GE0/0/1 as an example:
[SwitchC] display dhcp snooping interface gigabitethernet 0/0/1 DHCP snooping running information for interface GigabitEthernet0/0/1 : DHCP snooping : Enable Trusted interface : No Dhcp user max number : 20 Current dhcp and nd user number : 0 Check dhcp-giaddr : Enable Check dhcp-chaddr : Enable Alarm dhcp-chaddr : Enable Alarm dhcp-chaddr threshold : 120 Discarded dhcp packets for check chaddr : 0 Check dhcp-request : Enable Alarm dhcp-request : Enable Alarm dhcp-request threshold : 120 Discarded dhcp packets for check request : 0 Check dhcp-rate : Disable (default) Alarm dhcp-rate : Disable (default) Alarm dhcp-rate threshold : 500 Discarded dhcp packets for rate limit : 0 Alarm dhcp-reply : Disable (default)
SwitchC configuration file
# sysname SwitchC # vlan batch 10 100 # dhcp enable # dhcp snooping enable ipv4 dhcp snooping check dhcp-rate enable dhcp snooping check dhcp-rate 90 dhcp snooping alarm dhcp-rate enable dhcp snooping alarm dhcp-rate threshold 500 arp dhcp-snooping-detect enable # dhcp server group dhcpgroup1 dhcp-server 10.2.1.2 0 # interface Vlanif10 ip address 192.168.1.1 255.255.255.0 dhcp select relay dhcp relay server-select dhcpgroup1 # interface Vlanif100 ip address 10.1.1.2 255.255.255.0 # interface GigabitEthernet0/0/1 port link-type access port default vlan 10 dhcp snooping enable dhcp snooping check dhcp-giaddr enable dhcp snooping check dhcp-request enable dhcp snooping alarm dhcp-request enable dhcp snooping alarm dhcp-request threshold 120 dhcp snooping check dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr threshold 120 dhcp snooping max-user-number 20 # interface GigabitEthernet0/0/2 port link-type access port default vlan 10 dhcp snooping enable dhcp snooping check dhcp-giaddr enable dhcp snooping check dhcp-request enable dhcp snooping alarm dhcp-request enable dhcp snooping alarm dhcp-request threshold 120 dhcp snooping check dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr enable dhcp snooping alarm dhcp-chaddr threshold 120 dhcp snooping max-user-number 20 # interface GigabitEthernet0/0/3 port link-type access port default vlan 100 # ip route-static 0.0.0.0 0.0.0.0 10.1.1.1 # return