配置DHCPv4中继
操作步骤
- 配置设备间的网络互连
# 配置DeviceA。
<HUAWEI> system-view [~HUAWEI] sysname DeviceA [*HUAWEI] commit [~DeviceA] vlan batch 100 200 [*DeviceA] interface 100ge 1/0/1 [*DeviceA-100GE1/0/1] portswitch [*DeviceA-100GE1/0/1] port link-type hybrid [*DeviceA-100GE1/0/1] port hybrid pvid vlan 200 [*DeviceA-100GE1/0/1] port hybrid untagged vlan 200 [*DeviceA-100GE1/0/1] quit [*DeviceA] interface 100ge 1/0/2 [*DeviceA-100GE1/0/2] portswitch [*DeviceA-100GE1/0/2] port link-type hybrid [*DeviceA-100GE1/0/2] port hybrid pvid vlan 100 [*DeviceA-100GE1/0/2] port hybrid untagged vlan 100 [*DeviceA-100GE1/0/2] quit [*DeviceA] interface vlanif 200 [*DeviceA-Vlanif200] ip address 10.10.20.1 24 [*DeviceA-Vlanif200] quit [*DeviceA] commit
# 配置DeviceB。
<HUAWEI> system-view [~HUAWEI] sysname DeviceB [*HUAWEI] commit [~DeviceB] vlan batch 200 [*DeviceB] interface 100ge 1/0/1 [*DeviceB-100GE1/0/1] portswitch [*DeviceB-100GE1/0/1] port link-type hybrid [*DeviceB-100GE1/0/1] port hybrid pvid vlan 200 [*DeviceB-100GE1/0/1] port hybrid untagged vlan 200 [*DeviceB-100GE1/0/1] quit [*DeviceB] interface vlanif 200 [*DeviceB-Vlanif200] ip address 10.10.20.2 24 [*DeviceB-Vlanif200] quit [*DeviceB] commit
- 配置DHCPv4中继。
# 在DeviceA的接口VLANIF100下使能DHCPv4中继功能,并配置DHCPv4服务器的IPv4地址。
[~DeviceA] dhcp enable [*DeviceA] interface vlanif 100 [*DeviceA-Vlanif100] ip address 10.20.20.1 24 [*DeviceA-Vlanif100] dhcp select relay [*DeviceA-Vlanif100] dhcp relay server-ip 10.10.20.2 [*DeviceA-Vlanif100] quit [*DeviceA] commit
- 配置DHCPv4服务器。
# 在DeviceB上配置基于全局地址池的DHCPv4服务器功能。
[~DeviceB] dhcp enable [*DeviceB] interface vlanif 200 [*DeviceB-Vlanif200] dhcp select global [*DeviceB-Vlanif200] quit [*DeviceB] ip pool pool1 [*DeviceB-ip-pool-pool1] network 10.20.20.0 mask 24 [*DeviceB-ip-pool-pool1] gateway-list 10.20.20.1 [*DeviceB-ip-pool-pool1] option121 ip-address 10.10.20.0 24 10.20.20.1 [*DeviceB-ip-pool-pool1] quit [*DeviceB] commit
- 配置路由。
# 在DeviceA上配置缺省路由。
[~DeviceA] ip route-static 0.0.0.0 0.0.0.0 10.10.20.2 [*DeviceA] commit
# 在DeviceB上配置静态路由。
[~DeviceB] ip route-static 10.20.20.0 255.255.255.0 10.10.20.1 [*DeviceB] commit
检查配置结果
# 在DeviceA上执行命令display dhcp relay interface vlanif 100命令用来查看DHCPv4中继的配置信息。
[~DeviceA] display dhcp relay interface vlanif 100 Server IP address [00] : 10.10.20.2 Gateway address in use : 10.20.20.1 Gateway switch : Disable
# 在DHCPv4客户端上查看IPv4地址信息,可以看到已经成功获取到IPv4地址。
配置脚本
-
# sysname DeviceA # vlan batch 100 200 # dhcp enable # interface Vlanif100 ip address 10.20.20.1 255.255.255.0 dhcp select relay dhcp relay server-ip 10.10.20.2 # interface Vlanif200 ip address 10.10.20.1 255.255.255.0 # interface 100GE1/0/1 port link-type hybrid port hybrid pvid vlan 200 port hybrid untagged vlan 200 # interface 100GE1/0/2 port link-type hybrid port hybrid pvid vlan 100 port hybrid untagged vlan 100 # ip route-static 0.0.0.0 0.0.0.0 10.10.20.2 # return
-
# sysname DeviceB # vlan batch 200 # dhcp enable # ip pool pool1 gateway-list 10.20.20.1 network 10.20.20.0 mask 255.255.255.0 option121 ip-address 10.10.20.0 24 10.20.20.1 # interface Vlanif200 ip address 10.10.20.2 255.255.255.0 dhcp select global # interface 100GE1/0/1 port link-type hybrid port hybrid pvid vlan 200 port hybrid untagged vlan 200 # ip route-static 10.20.20.0 255.255.255.0 10.10.20.1 # return
