How DHCP Works
When a machine joins a new network, it must be discoverable by
other machines. But first the new machine doesn’t know anything
but its own MAC address. So How to make itself discoverable? It will
first do a “DHCP Discover”.
The new machine sent a broadcast packet with IP address 0.0.0.0
and destination IP address 255.255.255.255. Broadcast packets
encapsulate UDP, and UDP encapsulates BOOTP. In fact, DHCP is an
enhanced version of BOOTP, but if you go to capture packets, it is
likely that the name you see is still the BOOTP protocol.
In this broadcast package, the newcomer is yelling: I am new (Boot
request), my MAC address is this, I don’t have an IP yet, who can
rent me an IP address!
The packet format looks like:
The DHCP server then knows immediately the new machine had
come. At this time, we can appreciate the unique importance of the
MAC address. When a machine joins a network with its own MAC
address, the MAC is its only identity. If this is duplicated, there is no
way to configure it.
Only if the MAC is unique, the DHCP server can know that this is a
newcomer and needs to lease an IP address to it. This process is
called DHCP Offer. At the same time, the DHCP Server reserves the
IP address provided to it for this client, so that other DHCP clients
will not be assigned this IP address.
The format of the DHCP Offer looks like:
The DHCP Server still uses the broadcast address as the destination
address, because the new person requesting an IP assignment does
not have his own IP yet. The DHCP Server replies with an IP and in
addition to this, the server also sends information such as the
subnet mask, gateway, and IP address lease period.
If there are multiple DHCP servers, the new machine selects one of
the DHCP Offers, usually the one that arrives first, and sends a
DHCP Request broadcast packet to the network, which contains the
client’s MAC address, the IP address in the accepted lease, and the
DHCP server that provided the lease. Then tell all DHCP Servers
which IP address it will accept, and other DHCP servers to revoked
the other offered IPs.
At this time, since the final confirmation from the DHCP Server has
not been obtained, the client still uses 0.0.0.0 as the source IP
address and 255.255.255.255 as the destination address for
broadcasting. In BOOTP, accept the IP assigned by a DHCP Server.
When the DHCP Server receives the client’s DHCP request, it will
broadcast and return a DHCP ACK message to the client, indicating
that the client’s selection has been accepted, and put the legal lease
information of the IP address and other configuration information
into the the broadcast packet.
IP Address Recovery and Renewal
When 50% of the lease period has passed, the client will directly
send a DHCP request message packet to the DHCP Server that
provides it with an IP address.
When the client receives the DHCP ACK message package
responded by the server, it will update its configuration according to
the new lease provided in the package and other updated TCP/IP
parameters. In this way, the IP lease update is complete.
Conclusion
The DHCP protocol is mainly used to lease IP addresses to
customers. It is very similar to a real estate agency. To
negotiate, sign a contract, and renew the lease, the broadcast
cannot “snatch the order”;
•The DHCP protocol can recommend “renovation team” PXE to
customers, and can install the operating system, which is very
useful in the field of cloud computing.