DHCP(Dynamic Host Configuration Protocol)动态主机配置协议,是一个应用层协议。当我们将客户主机IP地址设置为动态获取方式时,DHCP服务器就会根据DHCP协议给客户端分配IP,使得客户机能够利用这个IP上网。
DHCP前身是BOOTP,在Linux的网卡配置中也能看到显示的是BOOTP,DHCP引进一个BOOTP没有的概念:租约。BOOTP分配的地址是永久的,而DHCP分配的地址是可以有期限的(默认是一天)。
DHCP采用C/S模式,一个是服务器端,另一个是客户端。
AR2配置
<Huawei>sy
[Huawei]dhcp enable //开启DHCP服务
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 192.168.1.254 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip address 192.168.2.254 24
[Huawei-GigabitEthernet0/0/1]q
[Huawei]ip pool dhcp_1 //创建一个名为dhcp_1的DHCP地址池
[Huawei-ip-pool-dhcp_1]network 192.168.1.0 //声明可用网段为192.168.1.0
[Huawei-ip-pool-dhcp_1]gateway-list 192.168.1.254 //声明该网段的网关192.168.1.254
[Huawei-ip-pool-dhcp_1]lease day 3 //设置租期为3天(默认一天)
[Huawei-ip-pool-dhcp_1]excluded-ip-address 192.168.1.1 192.168.1.2 //排除不使用的地址
[Huawei-ip-pool-dhcp_1]dns-list 114.114.114.114 //设置DNS服务器地址
[Huawei-ip-pool-dhcp_1]q
[Huawei]ip pool dhcp_2
[Huawei-ip-pool-dhcp_2]network 192.168.2.0
[Huawei-ip-pool-dhcp_2]gateway-list 192.168.2.254
[Huawei-ip-pool-dhcp_2]excluded-ip-address 192.168.2.1 192.168.2.2
[Huawei-ip-pool-dhcp_2]dns-list 8.8.8.8
[Huawei-ip-pool-dhcp_2]q
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]dhcp select global //接口视图下使用全局地址池的DHCP服务
测试结果