一、DHCP介绍
DHCP(Dynamic Host Configuration Protocol)动态主机配置协议,它可以自动为客户机分配IP地址、子网掩码以及缺省网关、DNS服务器的IP地址等。
ps:华为设备dhcp地址池默认分配是从大到小。
二、DHCP实验目的
实现PC1和PC2获取到IP地址;
PC1可以和PC2互通。
三、实验拓扑
四、实验配置
(1)PC1,PC2选择为DHCP自动获取。
(2)接入交换机配置
<Huawei>sys
#进入系统视图
[Huawei]sysname acsw
#修改交换机名称为acsw
[acsw]vlan batch 10 20
#创建vlan10和20
[acsw]un in en
#关闭日志提示
[acsw]interface g0/0/1
#进入接口
[acsw-GigabitEthernet0/0/1]port link-type access
#接口配成access模式
[acsw-GigabitEthernet0/0/1]port default vlan 10
#配置接口VLAN 10
[acsw-GigabitEthernet0/0/1]int g0/0/2
[acsw-GigabitEthernet0/0/2]port link-type access
[acsw-GigabitEthernet0/0/2]port default vlan 20
[acsw-GigabitEthernet0/0/2]q
[acsw]int g0/0/3
[acsw-GigabitEthernet0/0/3]port link-type trunk
#接口配成trunk模式
[acsw-GigabitEthernet0/0/3]port trunk allow-pass vlan all
#允许所有vlan通过
[acsw-GigabitEthernet0/0/3]q
#退出
(3)核心交换机配置
<Huawei>system-view
[Huawei]sysname coresw
[coresw]un in en
[coresw]int g0/0/1
[coresw-GigabitEthernet0/0/1]port link-type trunk
[coresw-GigabitEthernet0/0/1]q
[coresw]dhcp enable
[coresw]ip pool vlan10
#创建地址池名字是vlan10
[coresw-ip-pool-vlan10]network 192.168.10.0 mask 24
#地址池下发网段
[coresw-ip-pool-vlan10]gateway-list 192.168.10.254
#地址池下发网关
[coresw-ip-pool-vlan10]dns-list 8.8.8.8
#地址池下发dns地址
[coresw-ip-pool-vlan10]excluded-ip-address 192.168.10.101 192.168.10.253
#地址不下发范围
[coresw-ip-pool-vlan10]lease day 3
#租期为3天
[coresw-ip-pool-vlan10]q
[coresw]ip pool vlan20
[coresw-ip-pool-vlan20]network 192.168.20.0 mask 24
[coresw-ip-pool-vlan20]gateway-list 192.168.20.254
[coresw-ip-pool-vlan20]dns-list 114.114.114.114
[coresw-ip-pool-vlan20]excluded-ip-address 192.168.20.101 192.168.20.253
[coresw-ip-pool-vlan20]lease day 5
[coresw-ip-pool-vlan20]q
[coresw]vlan batch 10 20
[coresw]int Vlanif 10
[coresw-Vlanif10]ip add 192.168.10.254 24
[coresw-Vlanif10]dhcp select global
#在vlan10 启用dhcp服务
[coresw-Vlanif10]q
[coresw]int Vlanif 20
[coresw-Vlanif20]ip add 192.168.20.254 24
[coresw-Vlanif20]dhcp select global
[coresw-Vlanif20]q
[coresw]interface g0/0/1
[coresw-GigabitEthernet0/0/1]port link-type trunk
[coresw-GigabitEthernet0/0/1]port trunk allow-pass vlan all
(4)验证
PC1和PC2自动获取到IP地址。
PC1和PC2互通,配置成功。