Minimal Dhcp
Modified: August 16, 2024
Published: December 17, 2018
Tags:
The Dynamic Host Configuration Protocol (DHCP) is a network management protocol used on UDP/IP networks whereby a DHCP server dynamically assigns an IP address and other network configuration parameters to each device on a network so they can communicate with other IP networks.
How it works internally, in a nutshell, is like this:
- The device broadcasts a request called a DHCPDISCOVER request, looking for a server on the network that can send out DHCP configuration information.
How and where does the device broadcast if it doesn’t know anything about the network?
It sends a DHCPDISCOVER packet to the broadcast MAC address (FF:FF:FF:FF:FF:FF) at Layer 2 and the broadcast IP address (255.255.255.255) at Layer 3.
Why both MAC and IP address?
- Layer 2 Broadcast: Ensures that the message reaches all network devices on the local Ethernet segment, especially within the same switch or hub.
- Layer 3 Broadcast: Ensures that the message is broadcast to all devices within the same IP subnet, including those that may be separated by routers or other Layer 3 devices, provided they allow broadcast traffic.
What is a MAC address?
- Unique identifier for all network devices. No two devices will have the same MAC address.
- IEEE gives an OUI (Organizationally Unique Identifier), which is the first 24 bits of the MAC address, to manufacturers.
- Overall, it is 48 bits long; 24 bits for the OUI and 24 bits for the device identifier.
If there’s such a server and it’s working correctly, it responds with a DHCPOFFER message specifying the IP address and other configuration data that is available.
- This DHCPOFFER is usually sent as a unicast to the client’s MAC address, but some servers might also broadcast the DHCPOFFER if they are unsure whether the client has received it (particularly if the client does not yet have an IP address).
If the device accepts what’s on offer, it sends a DHCPREQUEST to reserve the IP address.
- If multiple DHCP servers send offers, then the client chooses one and sends a request to that server.
- The DHCPREQUEST message is broadcast to inform all DHCP servers on the network that it has selected an offer from one specific server.
DHCPACK (Server Acknowledgment)
- The selected DHCP server responds with a DHCPACK (Acknowledgment) message.
- The DHCPACK message contains the finalized IP address lease and other network configuration parameters (subnet mask, gateway, DNS servers, etc.).
- This message is typically unicast to the client, confirming that the IP address and configuration have been successfully allocated.
It will help me to improve/learn.