拓扑图
一、SW2 交换机设置
<Huawei>sys
[Huawei]sys SW2
# 关闭提示
[Huawei]un in en
# 批量创建 VLAN
[SW2]vlan batch 10 20
# 把接口加入 VLAN
[SW2]int e0/0/1
[SW2-Ethernet0/0/1]p l a
[SW2-Ethernet0/0/1]p d v 10
[SW2-Ethernet0/0/1]int e0/0/2
[SW2-Ethernet0/0/2]p l a
[SW2-Ethernet0/0/2]p d v 20
[SW2-Ethernet0/0/2]int e0/0/3
[SW2-Ethernet0/0/3]p l t
[SW2-Ethernet0/0/3]p t a v a
二、SW1 交换机设置
1、创建 VLAN
<Huawei>sys
[Huawei]sys SW1
# 关闭消息提示
[SW1]un in en
# 批量创建 VLAN
[SW1]vlan batch 10 20
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v a
2、配置 DHCP 地址池
# 开启DHCP功能
[SW1]dhcp enable
# 创建地址池
[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
[SW1-ip-pool-dhcp10]dns-list 114.114.114.114
[SW1]ip pool dhcp20
[SW1-ip-pool-dhcp20]network 192.168.20.0 mask 24
[SW1-ip-pool-dhcp20]gateway-list 192.168.20.1
[SW1-ip-pool-dhcp20]dns-list 114.114.114.114
3、配置IP并开启DHCP
# 配置IP
[SW1]int vlanif 10
[SW1-Vlanif10]ip addr 192.168.10.1 24
# 开启接口的全局DHCP
[SW1-Vlanif10]dhcp select global
[SW1-Vlanif10]int vlanif 20
[SW1-Vlanif20]ip addr 192.168.20.1 24
[SW1-Vlanif20]dhcp select global
4、查看地址池
<SW1>dis ip pool
-----------------------------------------------------------------------
Pool-name : dhcp10
Pool-No : 0
Position : Local Status : Unlocked
Gateway-0 : 192.168.10.1
Mask : 255.255.255.0
VPN instance : --
-----------------------------------------------------------------------
Pool-name : dhcp20
Pool-No : 1
Position : Local Status : Unlocked
Gateway-0 : 192.168.20.1
Mask : 255.255.255.0
VPN instance : --
IP address Statistic
Total :506
Used :0 Idle :506
Expired :0 Conflict :0 Disable :0
5、查看指定地址池
<SW1>dis ip pool name dhcp10
Pool-name : dhcp10
Pool-No : 0
Lease : 1 Days 0 Hours 0 Minutes
Domain-name : -
DNS-server0 : 114.114.114.114
NBNS-server0 : -
Netbios-type : -
Position : Local Status : Unlocked
Gateway-0 : 192.168.10.1
Mask : 255.255.255.0
VPN instance : --
-----------------------------------------------------------------------------
Start End Total Used Idle(Expired) Conflict Disable
-----------------------------------------------------------------------------
192.168.10.1 192.168.10.254 253 0 253(0) 0 0
-----------------------------------------------------------------------------
7、查看指定地址池情况
<SW1>dis ip pool name dhcp10 used
三、查看IP
PC1>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe2a:e09
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.10.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.10.1
Physical address..................: 54-89-98-2A-0E-09
DNS server........................: 114.114.114.114
PC2>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fee3:6765
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-E3-67-65
DNS server........................: 114.114.114.114