锐捷网管交换机DHCP按用户类分配地址配置举例

一、组网需求
如图所示,Device A作为DHCP服务器为客户端分配IP地址和其他网络配置参数;Device B作为DHCP中继在客户端与服务器之间转发DHCP报文。现要求实现:如果Device A接收到的请求报文中带有Option 82,则为该客户端分配地址范围192.1.1.200到192.1.1.254的IP地址;否则,为该客户端分配地址范围192.1.1.1到192.1.1.199的IP地址。
按用户类分配地址配置组网图

二、 配置要点
●配置Device A
○ 配置接口的IP地址。
○ 开启DHCP中继功能。
○ 开启Option82功能。

● 配置Device B
○ 配置接口的IP地址。
○ 配置从Device B到Device A的接口GigabitEthernet 0/1的路由。
○ 开启DHCP Server服务,配置地址池的参数。
○ 添加指定的用户类规则。

三、配置步骤
(1) 配置Device A
# 配置接口的IP地址。
DeviceA> enable
DeviceA# configure terminal
DeviceA(config)# interface gigabitethernet 0/1
DeviceA(config-if-GigabitEthernet 0/1)# ip address 192.1.1.1 255.255.255.0
DeviceA(config-if-GigabitEthernet 0/1)# exit
DeviceA(config)# interface gigabitethernet 0/2
DeviceA(config-if-GigabitEthernet 0/2)# ip address 172.2.2.2 255.255.255.0
DeviceA(config-if-GigabitEthernet 0/2)# exit

# 开启DHCP中继功能。
DeviceA(config)# service dhcp

# 添加DHCP服务器的地址。
DeviceA(config)# ip helper-address 172.2.2.1

# 开启Option82功能。
DeviceA(config)# ip dhcp relay information option82

(2) 配置Device B
# 配置接口的IP地址。
DeviceB> enable
DeviceB# configure terminal
DeviceB(config)# interface gigabitethernet 0/1
DeviceB(config-if-GigabitEthernet 0/1)# ip address 172.2.2.1 255.255.255.0
DeviceB(config-if-GigabitEthernet 0/1)# exit

# 配置到192.1.1.0/24网段的静态路由。
DeviceB(config)# ip route 192.1.1.0 255.255.255.0 gigabitethernet 0/1

# 启用DHCP Server功能。
DeviceB(config)# service dhcp

# 配置用户类规则。
DeviceB(config)# ip dhcp class myclass
DeviceB(config-dhcp-class)# relay agent information
DeviceB(config-dhcp-class-relayinfo)# relay-information hex 060223*

# 创建地址池并配置相关网络参数。
DeviceB(config)# ip dhcp pool pool1
DeviceB(dhcp-config)# network 192.1.1.0 255.255.255.0
DeviceB(dhcp-config)# default-router 192.1.1.1
DeviceB(dhcp-config)# dns-server 192.1.1.2

# 设置匹配用户类时分配地址网段。
DeviceB(dhcp-config)# class myclass
DeviceB(config-dhcp-pool-class)# address range 192.1.1.200 192.1.1.254
DeviceB(config-dhcp-pool-class)# exit

(3) 配置Host启动DHCP获取地址的功能。

四、验证配置结果
在Device B捕获报文,查看匹配用户类规则的终端申请到的IP地址范围为192.1.1.200~192.1.1.254;不匹配时,申请到的IP地址范围为192.1.1.1~192.1.1.199。

五、配置文件
●Device A的配置文件
hostname DeviceA
!
service dhcp
ip helper-address 172.2.2.1
ip dhcp relay information option82
!

interface gigabitethernet 0/1
ip address 192.1.1.1 255.255.255.0
exit
interface gigabitethernet 0/2
ip address 172.2.2.2 255.255.255.0
!
● Device B的配置文件
hostname DeviceB
!
ip route 192.1.1.0 255.255.255.0 gigabitethernet 0/1
service dhcp
!
interface gigabitethernet 0/1
ip address 172.2.2.1 255.255.255.0
!
ip dhcp class myclass
relay agent information
relay-information hex 060223*
!
ip dhcp pool pool1
network 192.1.1.0 255.255.255.0
default-router 192.1.1.1
dns-server 192.1.1.2
class myclass
address range 192.1.1.200 192.1.1.254
!

六、常见错误
● 没有启动DHCP Relay功能。
●没有配置DHCP Relay与DHCP Server之间的路由。
●没有配置DHCP 服务器IP地址。

ICP备案号:晋ICP备18007549号-1
站长微信:13613567205