1.DHCP概述
在IP网络环境中,设备间要通信或访问网络,必须获得IP地址。IP地址有2种设置方式:静态配置和动态获取。
静态配置,需要手工配置IP地址,子网掩码,默认网关,DNS等信息;
动态获取,则由DHCP服务器自动分配上诉信息。
动态获取使用的协议是DHCP。有两个优点:
对使用者来说,无需关心所在的网络细节,接入网线(Wifi)即可访问网络;
对网络管理者来说,可以简化网络配置和运维。
2. DHCP RFC
Abstract
The Dynamic Host Configuration Protocol (DHCP) provides a framework
for passing configuration information to hosts on a TCPIP network.
DHCP is based on the Bootstrap Protocol (BOOTP) [7], adding the
capability of automatic allocation of reusable network addresses and
additional configuration options [19]. DHCP captures the behavior of
BOOTP relay agents [7, 21], and DHCP participants can interoperate
with BOOTP participants [9].
Introduction
The Dynamic Host Configuration Protocol (DHCP) provides configuration
parameters to Internet hosts. DHCP consists of two components: a
protocol for delivering host-specific configuration parameters from a
DHCP server to a host and a mechanism for allocation of network
addresses to hosts.
DHCP is built on a client-server model, where designated DHCP server
hosts allocate network addresses and deliver configuration parameters
to dynamically configured hosts. Throughout the remainder of this
document, the term “server” refers to a host providing initialization
parameters through DHCP, and the term “client” refers to a host
requesting initialization parameters from a DHCP server.
3. DHCP总体流程
1. DHCPDISCOVER
Client在首次启动时,需要向网络获取IP地址,会发送一个广播消息(目的IP地址为一个L3的广播地址:255.255.255.255, 目的MAC为一个L2的广播地址:FF-FF-FF-FF-FF-FF, 源IP地址为0.0.0.0, 源MAC地址为客户端实际的MAC地址)。
2. DHCPOFFER
DHCP服务器收到discover消息后,从服务器的IP地址池里挑选一个没有被分配的IP地址,通过offer消息发给客户端。offer消息在L3是一个广播消息(目的地址为255.255.255.255),但在L2是一个单播消息(目的MAC地址为client的MAC地址)。
3. DHCPREQUEST
客户端收到Offer消息后
- 如果接受该IP地址,就回复request消息;
- 如果发现该IP地址已被使用,就回复decline消息
客户端如何发现该IP地址已被使用?
- 客户端通过广播ARP请求来判断该IP地址是否被使用,如果没有设备回复ARP请求,则证明该IP地址可以使用,不会冲突。
什么场景会出现IP地址冲突?
- 其他设备手工配置的静态IP地址,和DHCP服务器分配的地址一样
- DHCP服务器地址池不够用。TBD, 不够用的时候offer消息都不应该下发。?