DHCP Discover 消息的目的地址通常是广播地址 (Broadcast Address). 广播地址是一个特殊的 IP 地址,用于将消息发送到网络中的所有设备。在 IPv4 网络中,广播地址通常是目标 IP 地址为 255.255.255.255 的消息.
DHCP 续租过程
1. 当客户端的租期到达 50% 时会主动发送一个单播的 Request 进行 DHCP 续租.
2. 如果 Server 检查 Request 消息没有任何问题,直接回复 ACK 确认,并刷新租期.
3. 如果 50% 没有回应,会继续使用该 IP 地址,直到租期的 87.5%, 客户端广播发送 Request 进行续租,如果有 DHCP Server 回应可以进行续租,如果没有回应,将地址租期结束后重新进行租借过程.
DHCP 全局地址池
<Huawei> <Huawei> <Huawei>sy Enter system view, return user view with Ctrl+Z. [Huawei]sy R1 [R1]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. [R1]ip pool ? STRING<1-64> Pool name [R1]ip pool PC Info: It's successful to create an IP address pool. [R1-ip-pool-PC]network ? IP_ADDR<X.X.X.X> IP address [R1-ip-pool-PC]network 192.168.1.0 mask 24 [R1-ip-pool-PC]display this [V200R003C00] # ip pool PC network 192.168.1.0 mask 255.255.255.0 # return [R1-ip-pool-PC]q [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]ip address 192.168.1.254 24 Dec 19 2023 09:50:57-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. [R1-GigabitEthernet0/0/0]display this [V200R003C00] # interface GigabitEthernet0/0/0 ip address 192.168.1.254 255.255.255.0 # return [R1-GigabitEthernet0/0/0]ip pool PC [R1-ip-pool-PC]ga [R1-ip-pool-PC]gateway-list ? IP_ADDR<X.X.X.X> Gateway's IP address [R1-ip-pool-PC]gateway-list 192.168.1.254 [R1-ip-pool-PC]dns-list ? IP_ADDR<X.X.X.X> IP address [R1-ip-pool-PC]dns-list 114.114.114.114 [R1-ip-pool-PC]dis th [V200R003C00] # ip pool PC gateway-list 192.168.1.254 network 192.168.1.0 mask 255.255.255.0 dns-list 114.114.114.114 # return [R1-ip-pool-PC]lease day 0 hour 0 minute 30 [R1-ip-pool-PC]dis this [V200R003C00] # ip pool PC gateway-list 192.168.1.254 network 192.168.1.0 mask 255.255.255.0 lease day 0 hour 0 minute 30 dns-list 114.114.114.114 # return [R1-ip-pool-PC]q [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]dhcp select global
[R1]interface GigabitEthernet0/0/0 // 进入接口视图 [R1-GigabitEthernet0/0/0]ip address 192.168.1.254 255.255.255.0 // 配置 IP 地址 [R1-GigabitEthernet0/0/0]dhcp select global // 接口下使能全局地址池
[R1]display current-configuration // 查看配置
DHCP 接口地址池
<Huawei>sy Enter system view, return user view with Ctrl+Z. [Huawei]sy R1 [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]ip add 192.168.1.254 24 [R1-GigabitEthernet0/0/0] Dec 19 2023 11:00:18-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. [R1-GigabitEthernet0/0/0]q [R1]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]dhcp select interface [R1-GigabitEthernet0/0/0]dis th [V200R003C00] # interface GigabitEthernet0/0/0 ip address 192.168.1.254 255.255.255.0 dhcp select interface # return [R1-GigabitEthernet0/0/0]dhcp server dns-list 114.114.114.114 [R1-GigabitEthernet0/0/0]dhcp server lease day 0 hour 0 min 30
<R1>sy Enter system view, return user view with Ctrl+Z. [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]dhcp server ? dns-list Configure DNS servers domain-name Configure domain name excluded-ip-address Mark disable IP addresses import Imports the following network configuration parameters from a central server into local ip pool database: domain name, dns server and netbios server. lease Configure the lease of the IP pool nbns-list Configure the windows's netbios name servers netbios-type Netbios node type next-server The address of the server to use in the next step of the client's bootstrap process. option Configure the DHCP options option121 DHCP option 121 option184 DHCP option 184 recycle Recycle IP address static-bind Static bind [R1-GigabitEthernet0/0/0]dhcp server st [R1-GigabitEthernet0/0/0]dhcp server static-bind ? ip-address IP address for static bind [R1-GigabitEthernet0/0/0]dhcp server static-bind ip-address 192.168.1.51 ? mac-address MAC address for static bind [R1-GigabitEthernet0/0/0]dhcp server static-bind ip-address 192.168.1.51 mac-add ress ? MAC_ADDR<XXXX-XXXX-XXXX> MAC address [R1-GigabitEthernet0/0/0]dhcp server static-bind ip-address 192.168.1.51 mac-add ress 5489-981A-18A3 [R1-GigabitEthernet0/0/0]
<Huawei>sy [Huawei]sy R1 [R1]dhcp enable // 开启 DHCP 功能 [R1]int g0/0/0 // 进入接口视图 [R1-GigabitEthernet0/0/0]ip add 192.168.1.254 24 // 配置 IP 地址的掩码 [R1-GigabitEthernet0/0/0]dhcp select interface // 接口下使能接口地址池 [R1-GigabitEthernet0/0/0]dhcp server dns-list 114.114.114.114 // 设置 DNS [R1-GigabitEthernet0/0/0]dhcp server lease day 0 hour 0 min 30 // 设置租期 [R1-GigabitEthernet0/0/0]dhcp server excluded-ip-address 192.168.1.10 192.168.1.50 // 排除地址池中的地址 [R1-GigabitEthernet0/0/0]dhcp server static-bind ip-address 192.168.1.51 mac-address 5489-981A-18A3 // 静态绑定某个主机使用某个IP地址
DHCP 中继
PC 的 DHCP 广播报文单播发给 DHCP 服务器.
R1
<Huawei>sy Enter system view, return user view with Ctrl+Z. [Huawei]sy R1 [R1]int g0/0/1 [R1-GigabitEthernet0/0/1]ip add 192.168.1.254 24 [R1-GigabitEthernet0/0/1]int g0/0/0 [R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24 [R1-GigabitEthernet0/0/0] [R1]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. [R1]int g0/0/1 [R1-GigabitEthernet0/0/1]dhcp select ? global Local server interface Interface server pool relay DHCP relay [R1-GigabitEthernet0/0/1]dhcp select relay [R1-GigabitEthernet0/0/1]dhcp relay server-ip 12.1.1.2 [R1-GigabitEthernet0/0/1]
R2
<Huawei>sy Enter system view, return user view with Ctrl+Z. [Huawei]sy R2 [R2]int g0/0/0 [R2-GigabitEthernet0/0/0]ip add 12.1.1.2 24 [R2-GigabitEthernet0/0/0]q [R2]ping 192.168.1.254 PING 192.168.1.254: 56 data bytes, press CTRL_C to break Request time out Request time out Request time out
--- 192.168.1.254 ping statistics --- 3 packet(s) transmitted 0 packet(s) received 100.00% packet loss
[R2]ip route-static 192.168.1.0 24 12.1.1.1 [R2]ping 192.168.1.254 PING 192.168.1.254: 56 data bytes, press CTRL_C to break Reply from 192.168.1.254: bytes=56 Sequence=1 ttl=255 time=110 ms Reply from 192.168.1.254: bytes=56 Sequence=2 ttl=255 time=20 ms Reply from 192.168.1.254: bytes=56 Sequence=3 ttl=255 time=30 ms Reply from 192.168.1.254: bytes=56 Sequence=4 ttl=255 time=40 ms Reply from 192.168.1.254: bytes=56 Sequence=5 ttl=255 time=10 ms
--- 192.168.1.254 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 10/42/110 ms
[R2]ip pool PC [R2-ip-pool-PC]network 192.168.1.0 mask 24 [R2-ip-pool-PC]gateway-list 192.168.1.254 [R2-ip-pool-PC]dns-list 114.114.114.114 [R2-ip-pool-PC]lease day 0 hour 0 min 10 [R2-ip-pool-PC]excluded-ip-address 192.168.1.100 192.168.1.253
[R2-ip-pool-PC]dis th [V200R003C00] # ip pool PC gateway-list 192.168.1.254 network 192.168.1.0 mask 255.255.255.0 excluded-ip-address 192.168.1.100 192.168.1.253 lease day 0 hour 0 minute 10 dns-list 114.114.114.114 # return [R2-ip-pool-PC]q [R2]dhcp enable Info: The operation may take a few seconds. Please wait for a moment.done. [R2]int g0/0/0 [R2-GigabitEthernet0/0/0]dhcp select global [R2-GigabitEthernet0/0/0]