To explain how a DHCP Relay works first, we are going to refresh what a DHCP is and how it works.
DHCP, or Dynamic Host Configuration Protocol, is a network management protocol used on IP networks. It allows devices to automatically obtain IP addresses and other network configuration information from a DHCP server, such as subnet mask, default gateway, and DNS servers.
Here's how DHCP typically works:
- DHCP Discover: When a device, like a computer or smartphone, connects to a network, it sends a broadcast message called a DHCP Discover packet. This packet essentially asks, "Is there a DHCP server out there that can give me an IP address?"
- DHCP Offer: If there is a DHCP server on the network, it responds with a DHCP Offer packet. This packet contains an available IP address that the server is willing to lease to the device, along with other network configuration parameters.
- DHCP Request: Upon receiving the DHCP Offer, the device sends a DHCP Request packet, indicating that it accepts the offered IP address and network configuration.
- DHCP Acknowledgement: Finally, the DHCP server responds with a DHCP Acknowledgement packet, confirming that the IP address has been leased to the device for a certain period (lease time), and providing any additional configuration details.
The device then configures its network interface with the provided IP address and other settings. It can now communicate on the network using the assigned IP address.
DHCP leases are typically temporary. Devices must renew their leases periodically to maintain their network connectivity. If a device disconnects from the network or its lease expires, the leased IP address becomes available for reuse by another device.
But, what happens if the DHCP server is not located on the same subnet as the DHCP clients? Since most medium or large enterprises have networks segmented into multiple subnets and these subnets need an L3 device to communicate with each other, but router by default do not forward broadcast traffic, so all DHCP Discover packets will be dropped by routers and clients never receive a IP address. Well, this is where DHCP Relay comes into play.
DHCP Relay is a feature used in networks where DHCP servers are not located on the same subnet as the DHCP clients. It allows DHCP clients to obtain IP addresses and other network configuration information even when the DHCP server is on a different subnet.
Here's how DHCP Relay typically works:
- DHCP Discover: A DHCP client sends out a DHCP Discover broadcast message to obtain an IP address. However, if the DHCP server is not on the same subnet as the client, the broadcast message won't reach it.
- DHCP Relay Agent: A DHCP relay agent is configured on the local network router or switch interface that receives the DHCP Discover broadcast. This agent listens for DHCP broadcast messages and forwards them to a DHCP server on a different subnet.
- DHCP Relay Forwarding: The DHCP relay agent encapsulates the DHCP Discover message in a unicast packet and forwards it to the DHCP server's IP address. It also includes information about the original broadcast source, such as the client's MAC address and the relay agent's IP address.
- DHCP Server Response: The DHCP server receives the DHCP Discover message and processes it as usual. It selects an available IP address from its pool and sends a DHCP Offer message back to the relay agent's IP address.
- DHCP Relay Agent Decapsulation: The relay agent receives the DHCP Offer message, removes the encapsulation, and forwards the DHCP Offer message as a broadcast to the local subnet where the DHCP client resides.
- Client Configuration: The DHCP client receives the DHCP Offer message and responds with a DHCP Request message, indicating its acceptance of the offered IP address. The DHCP server then sends a DHCP Acknowledgement message, confirming the lease of the IP address to the client.
By using DHCP relay, DHCP clients can obtain IP addresses and network configuration information from DHCP servers located on different subnets, enabling efficient management of IP addresses across complex network infrastructures.