DHCP协商的4个过程

DHCP 客户端第一次登录网络的时候,也就是客户发现本机上没有任何 IP 数据设定,它会向网络发出一个 DHCP DISCOVER 的广播,以便定位DHCP服务器。

 

如果网络中存在DHCP服务器,那么它会响应DHCP DISCOVER广播。向DHCP CLIENT单播一条DHCP OFFER消息

======================================================================

一直很纠结这个DHCP OFFER

广播还是单播?书上的答案很直接:向DHCP客户端单播一条dhcp offer消息。

DHCP CLIENT没有IP地址,服务器怎么用单播来响应??这有点说不过去吧……

 

看看rfc2131上是怎么解释的:

----------------------------------------------rfc2131---------------------------------------------------------------

A server or relay agent sending or relaying a DHCP message directly to a DHCP client (i.e., not to a relay agent specified in the 'giaddr' field) SHOULD examine the BROADCAST bit in the 'flags' field. If this bit is set to 1, the DHCP message SHOULD be sent as an IP broadcast using an IP broadcast address (preferably 0xffffffff) as the IP destination address and the link-layer broadcast address as the link-layer destination address. If the BROADCAST bit is cleared to 0, the message SHOULD be sent as an IP unicast to the IP address specified in the 'yiaddr' field and the link-layer address specified in the 'chaddr' field. If unicasting is not possible, the message MAY be sent as an IP broadcast using an IP broadcast address (preferably 0xffffffff) as the IP destination address and the link- layer broadcast address as the link-layer destination address.


抓包看看

 

总之它就是单播……(至于为什么是单播目的地是150.125。我想可能是DHCP的记忆功能吧,因为我是release之前的地址就是它)

 

Offer消息包含来DHCP的配置参数

 

DHCP客户端会用DHCP Request响应DHCP Offer消息。请求DHCP offer消息中的IP地址。

 

DHCP服务器会用DHCP ACK来对进行响应。

 

4个步骤,简单理解

Client: 谁是DHCP服务器???我需要一个IP地址,你速度同我联系。

Server:我就是DHCP服务器,这个IP地址你看可以不?

Client:好,就这个了。

Server:那好,你从现在开始就用这个IP吧。