DHCP: 动态主机配置协议 -- 同一分发管理ip地址
基于UDP 67/68端口工作
网络中存在DHCP的服务器为需要自动生成ip地址的设备分配ip地址;--C/S模型
成为DHCP服务器的条件:
- 该设备存在接口或网卡连接到所要分发ip地址的广播域内
- 该接口或网卡必须已经配置合法ip地址,且可以正常通讯;
第一步: [Huawei]dhcp enable 先开启设备的dhcp服务 一台设备上可以创建多个池塘,但一个池塘只能服务一个广播域 第二步: [Huawei]ip pool wangcai 创建名为wangcai的dhcp池塘 第三步: [Huawei-ip-pool-wangcai]network 192.168.1.0 mask 24 绑定接口 第四步: [Huawei-ip-pool-wangcai]gateway-list 192.168.1.1 该网段网关地址 第五步: [Huawei-ip-pool-wangcai]dns-list 192.168.2.11 114.114.114.114 DNS服务器地址 第六步 [Huawei]interface Eth0/0/0 [Huawei-Ethernet0/0/0]dhcp select global 切记:最后还需要在路由器进行地址分配的接口上再单独开启dhcp服务
客户端基于UDP,源端口68,目标端口67进行广播请求 -- 源ip-0.0.0.0(无效地址,代表本地无地址)目255.255.255.255
服务器在收到客户端的请求后,回复提议-- 源端口67,目标68;源ip-本地地址,目标ip(255.255.255.255)华为设备的目标ip为计划分配给客户端的ip --- 主要还是靠目标的MAC地址来将提议发送给客户
客户端在收到提议后,若确定使用该ip,将应答服务端;服务端最终ack确认后,该ip地址才可以被真正的使用;
注:过程中服务端与客户端均会使用ARP来进行地址冲突检测,确认该地址唯一时,才进行分配和使用;
dhcp抓包过程;
[Huawei-ip-pool-a]excluded-ip-address 192.168.1.10 192.168.1.20 排除地址 -- 该池塘不能分配的ip地址
[Huawei-ip-pool-a]lease day 0 hour 0 minute 30 修改租期,默认24小时
实验部分:
[Huawei-ip-pool-a]display current-configuration
#
sysname Huawei
#
dhcp enable
#
ip pool b
gateway-list 192.168.2.1
network 192.168.2.0 mask 255.255.255.0
dns-list 192.168.1.2
#
ip pool a
gateway-list 192.168.1.1
network 192.168.1.0 mask 255.255.255.0
dns-list 192.168.1.2
#
aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher OOCM4m($F4ajUn1vMEIBNUw#
local-user admin service-type http
#
firewall zone Local
priority 16
#
interface Ethernet0/0/0
ip address 192.168.1.1 255.255.255.0
dhcp select global
#
interface Ethernet0/0/1
ip address 192.168.2.1 255.255.255.0
dhcp select global
[Huawei-ip-pool-a]dis ip interface brief
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 8
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 8
Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 192.168.1.1/24 up up
Ethernet0/0/1 192.168.2.1/24 up up
GigabitEthernet0/0/0 unassigned down down
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
GigabitEthernet0/0/3 unassigned down down
NULL0 unassigned up up(s)
Serial0/0/0 unassigned down down
Serial0/0/1 unassigned down down
Serial0/0/2 unassigned down down
Serial0/0/3 unassigned down down
[Huawei-ip-pool-a]
PC>ipconfig
Link local IPv6 address...........: fe80::5689:98ff:fe4a:742d
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.1.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.1.1
Physical address..................: 54-89-98-4A-74-2D
DNS server........................: 192.168.1.2
Link local IPv6 address...........: fe80::5689:98ff:fe97:2d3f
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.2.254
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.2.1
Physical address..................: 54-89-98-97-2D-3F
DNS server........................: 192.168.1.2