1、拓扑图

华为三层交换机 配置VLAN 基于全局开启DHCP_DNS

2、配置 VLAN

<SW1>sys

# 关闭消息提示
[SW1]undo info en

# 交换机命名
[Huawei]sys SW1

# 批量创建 VLAN 10 20
[SW1]vlan batch 10 20

# 配置 VLAN
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l a
[SW1-GigabitEthernet0/0/1]p d v 10
[SW1-GigabitEthernet0/0/1]int g0/0/2
[SW1-GigabitEthernet0/0/2]p l a
[SW1-GigabitEthernet0/0/2]p d v 20

3、配置 DHCP 地址池

# 开启 DHCP 功能
[SW1]dhcp enable

# 创建地址池 dhcp10
[SW1]ip pool dhcp10

# 配置网段地址
[SW1-ip-pool-dhcp10]network 192.168.10.0 mask 24

# 配置网关
[SW1-ip-pool-dhcp10]gateway-list 192.168.10.1

# 配置DNS
[SW1-ip-pool-dhcp10]dns-list 114.114.114.114

# 创建地址池 dhcp20
[SW1-ip-pool-dhcp10]ip pool dhcp20

# 配置网段地址
[SW1-ip-pool-dhcp20]network 192.168.20.0 mask 24

# 配置网关
[SW1-ip-pool-dhcp20]gateway-list 192.168.20.1

# 配置DNS
[SW1-ip-pool-dhcp20]dns-list 114.114.114.114

4、VLAN 配置 DHCP

# 进入 VLAN 10
[SW1-ip-pool-dhcp20]int vlan 10

# 配置IP
[SW1-Vlanif10]ip addr 192.168.10.1 24

# VLAN 10 选择 DHCP
[SW1-Vlanif10]dhcp select global

# 进入 VLAN 20
[SW1-Vlanif10]int vlan 20
[SW1-Vlanif20]ip addr 192.168.20.1 24
[SW1-Vlanif20]dhcp select global