Table of Contents I. Overview |
I. Overview
This document provides a technical understanding of a DHCP relay agent that is required in a multi-subnet environment where a DHCP client and a DHCP server reside in different subnets. Chapter II explains why these DHCP relay agents are needed in DHCP operations. Chapter III describes the basic principles of DHCP operations using a DHCP relay agent. Finally, in Appendix, specific message parameters used by DHCP relay agents in each DHCP procedure will be presented.
Before you read this document it is recommended that you refer to the companion documents, “Understanding the Basic Operations of DHCP” [2] and “Understanding the Detailed Operations of DHCP” [3].
II. Why are DHCP Relay Agents Needed in DHCP Operations?
Generally, DHCP messages are broadcasted. So, in order for the messages to be exchanged between a DHCP client (PC) and DHCP server, both the client and server have to reside on the same subnet. That is because routers do not forward any broadcast IP packet (i.e. one with a destination MAC address of FF:FF:FF:FF:FF:FF and a destination IP address of 255.255.255.255) to other interfaces. Thus a broadcast DHCP packet sent by a DHCP client cannot be delivered to DHCP server(s) on different subnet(s) through a router (shown in Figure 1 - (a)). This restriction requires all individual subnets have its own DHCP server for DHCP operation, which is practically not feasible in network operators' networks or corporate computer networks (too many DHCP servers are required in the network!).
To address this problem, the concept of a DHCP relay agent has long been adopted [1]. As shown in Figure 1 - (b), enabling the DHCP relay agent function in the router allows DHCP messages to be exchanged between a DHCP client and DHCP server residing on different subnets.1 The core function of this DHCP relay agent is to convert a broadcast DHCP packet into a unicast one, and forward it to a DHCP server.
Figure 1. Comparison of DHCP operations between networks with and without a DHCP relay agent
III. Basic Operations of DHCP Relay Agents
This chapter describes how a PC (e.g. PC1) on “1.1.1.0/24” subnet, as shown in Figure 1 - (b), can communicate with the DHCP server using a DHCP relay agent for all DHCP operations, such as IP address allocation/lease, IP address renewal and IP address release.
3.1 IP Address Allocation/Lease Procedure
The DHCP relay agent is located between a PC and DHCP server as shown in Figure 2. The DHCP relay agent receives DHCP Discover and Request messages broadcasted by the PC, and unicasts them directly to the DHCP server. At this point, the DHCP relay agent stores its IP address (the interface address at which it received the DHCP Discover/Request messages) in the “Relay Agent IP (=Gateway IP=giaddr)” field of the DHCP message to be relayed.
The DHCP server unicasts a DHCP Offer/Ack message, with the destination IP address set as the relay agent IP address, to the DHCP relay agent. The DHCP relay agent, after checking the “Broadcast Flag” field of the received message, replaces the destination IP address with the IP address of the PC (Broadcast Flag=0) or with the broadcast IP address (Broadcast Flag=1) depending on the “Broadcast Flag” value. It also replaces the source IP address with the IP address of the DHCP relay agent, and forwards the modified message to the PC.
Figure 2. IP address allocation/lease procedure in the network with a DHCP relay agent
1. DHCP Discover
As described in the references [2], “Understanding the Basic Operations of DHCP”, and [3], “Understanding the Detailed Operations of DHCP”, a DHCP client broadcasts a DHCP Discover message on the physical Ethernet subnet to discover all DHCP servers available on the subnet. Upon receiving packets that have a UDP destination port set to 67 (DHCP Discover/Request), a DHCP relay agent replaces the values in the fields of the packets as follows, and then unicasts the modified message to a DHCP server:
2. DHCP Offer
The DHCP server, by referring to the relay agent IP address (giaddr) in a DHCP Discover message, selects an IP address to allocate to the DHCP client from an IP pool, and sends a DHCP Offer message with the destination IP address set as the relay agent IP address2. The DHCP relay agent, when receiving the message, replaces the values in the fields of the packets as follows, and then sends the modified message on to the DHCP client (PC):
3. DHCP Request
The DHCP client (PC) which received the DHCP Offer message broadcasts a DHCP Request message on the physical Ethernet subnet to request network information data such as IP addresses. The DHCP relay agent, upon receiving this message, replaces the values in the fields (same as in the DHCP Discover message) of the packets as follows, and then unicasts the message to the DHCP server:
4. DHCP Ack
The DHCP server sends a DHCP Ack message with the destination IP address set as the relay agent IP address (giaddr)3. The DHCP relay agent, upon receiving this message, replaces the values in the fields of the packets as follows, and then unicasts the message to the DHCP client (PC):
3.2 IP Address Renewal Procedure
According to the reference [1], a DHCP client (PC) keeps/stores the DHCP server IP address acquired through a DHCP Ack message (in the DHCP Server Identifier field) during the IP address allocation procedure. Then, if it needs to use the IP address beyond the lease duration, it sends a DHCP Request message to the DHCP server, through unicasting, not broadcasting. And the DHCP server, in respond to the message, unicasts a DHCP Ack message to the DHCP client.
As such, in case DHCP messages are to be unicasted, the DHCP relay agent does not need to play its role (of converting a broadcast message to a unicast one) for DHCP operations. So, as can be seen in Figure 3, the DHCP relay agent is not involved in any DHCP operations during the IP address renewal procedure.
Figure 3. IP address renewal procedure in the network with a DHCP relay agent
1. DHCP Request
The DHCP client (PC) unicasts a DHCP Request message with the destination IP address set as the IP address of a DHCP server. Thus, a DHCP relay agent does not receive this message. In other words, no field of the DHCP Request message is replaced by the DHCP relay agent during the IP address renewal procedure.
2. DHCP Ack
The DHCP server unicasts a DHCP Ack message with the destination IP address set as the IP address of the DHCP client (PC). Again, a DHCP relay agent does not receive this message. In other words, no field of the DHCP Ack message is replaced by the DHCP relay agent during the IP address renewal procedure.
3.3 IP Address Release Procedure
According to the reference [1], RFC 1542, when an IP address is released, a DHCP client (PC) unicasts a DHCP Release message to a DHCP server directly. Thus, a DHCP relay agent is not involved in the IP address release procedure as shown in Figure 4.
Figure 4. IP address release procedure in the network with a DHCP relay agent
1. DHCP Release
A DHCP client unicasts a DHCP Release message with the destination IP address set as the IP address of a DHCP server. Thus a DHCP relay agent does not receive this message. In other words, no fields of the DHCP Ack message is replaced by the DHCP relay agent during the IP address release procedure.
References
[1] W. Wimer, “Clarifications and Extensions for the Bootstrap Protocol”, RFC 1542, Standard, October 1993.
[2] Netmanias Technical Document, “Understanding the Basic Operations of DHCP”, October 2013
[3] Netmanias Technical Document, “Understanding the Detailed Operations of DHCP”, October 2013
Footnotes
1 Generally, routers and L3 switches support all of DHCP relay agent functions.
2 Unless the IP address of a DHCP relay agent is set as “0.0.0.0”, a DHCP server always unicasts a DHCP Offer message to the DHCP relay agent regardless of the Broadcast Flag value.
3 Unless the IP address of a DHCP relay agent is set as “0.0.0.0”, a DHCP server always unicasts a DHCP Ack message to the DHCP relay agent regardless of the Broadcast Flag value.
Appendix − Format of DHCP Messages in a Network with DHCP Relay Agents
This appendix provides specific examples of DHCP message parameters that are replaced by a DHCP relay agent during DHCP procedures. However, in case of IP address renewal and release procedures, a DHCP relay agent does NOT replace any part of DHCP messages. Thus, all messages related to those procedures are excluded in this appendix.
DHCP Discover Message
Figure 5. DHCP Discover message in IP address allocation/lease procedure
Ethernet Header
IP Header
DHCP Message Payload
DHCP Offer Message
Figure 6. DHCP Offer message in IP address allocation/lease procedure
Ethernet Header
Note: In this example, as we assumed that the “Broadcast Flag” value is set to 1, the relay agent broadcasts the message.
IP Header
Note: In this example, as we assumed that the “Broadcast Flag” value is set to 1, the relay agent broadcasts the message.
DHCP Request Message
Figure 7. DHCP Request message in IP address allocation/lease procedure
Ethernet Header
IP Header
DHCP Message Payload
DHCP Ack Message
Figure 8. DHCP Ack message in IP address allocation/lease procedure
Ethernet Header
IP Header
Note: In this example, as we assumed that the “Broadcast Flag” value is set to 1, the relay agent broadcasts the message.
Awesome article. Haven't seen such a detailed and clear discription of the topic.
Hi Varun, Thank you for your compliment :-)
super details thanks a lot for a great article...
I ever r seen this much clear explanatioin on dhcp relay agent. Thank you :)
This is by far the best explanation i have seen on DHCP.. thank a ton !!!
Best article written on DHCP to the date.
Thank you for your compliment. I'm glad you liked it.
excellent!!! a crystal clear explanation with enormous details... verymuch appreciated... hats off...
Wonderful article !! Thanks for the insight, it's been helpful in understanding DHCP
The document is pretty helpful! Thanks for sharing such an enormous details article.
Excellent document. Very useful.Thanks for sharing
good explanation Thanks
Very, very gooood. Big Thanks !!!
omg! this is super work.
the best i ever seen
thanks !!
you did a well job but smothing you need to edit in relp port it should be 67
wonderful article...Really appriciated..Great Thanks...
Excellent Article.
Is it possible to know which editing tool you have used to draw such a beautiful detailed explanaions with respect to protocol ?
We mainly use Microsoft Visio as a drawing tool.
How does the the relay agent know the DHCP server IP and MAC?
The DHCP server IP should be configured on relay agent,
but MAC address of the DHCP server does not need to be known by the relay agent.
The source port and destination port used between router and DHCP server must be 67 in both direction.
Nice work, this gives a good explanation.
Very informative article !! A quick note though, I think the source port from the relay agent should be 67 itself otherthan 68 whent the relay agent unicasts the packets to the Server. Correct me if i am wrong.
Very useful article on DHCP relay agent
I've been surfing internet to get packet level explaination specifially with DHCP Server located on a different network, this is the best explaination I have ever came across.
- Great Job. I can imagine your efforts and time behind this.
Cheers from Seattle, USA
It is possible to havce the same good lesson about DHCPv6 messages and if it possible understand better the transport between an client with DHCPv6 request over an IPv4 network backbone; the DHCP server is dual-stack ? Thank you too much
max@massimilianosbaraglia.it
Very well explained and easiest way with artifacts.
"GOOD WORK"
Wow supper ....
Vice nice explanation.
Can we configure any device except (router/switch) as DHCP relay agent?
If yes, then can we configure one port as DHCP client and other port as DHCP relay agent on this device (this device neither a router nor a switch)?
wonderful explination
Was looking for information on how DHCP identifies it came from which subnet? Nice Explaination. Thanks for taking time and efforts.
really nice content
Hi, The DHCPDISCOVER and DHCPREQUEST packets used as SIP the IP: 1.1.1.254, not the 100.1.1.254
Hi , If between Router (DHCP Relay) and DHCP Server , there is a Firewall , does it work?
In this case , Does the client Get IP address?
Hi , If between Router (DHCP Relay) and DHCP Server , there is a Firewall , does it work?
In this case , Does the client Get IP address?
Dear Johannes ,
I'm writing you as a fellow German bloke and wanted to ask whether you could guide mit to an authoritative source which states, what the default Source IP Address of a DHCPv4 Discover / Request from a client via Relay Agent is.
I'm asking this because refering to my tests Cisco Routers in this regard behave differently to other Network manufacturers:
Behaviour with Cisco Router:
eth0:192.168.1.1 eth1:10.0.0.1 10.0.0.254
DHCP-Client ------------- Cisco Router and IPv4 Relay Agent --------------- DHCP-Server
sip 0.0.0.0 ---> relayed with ----> sip: 192.168.1.1
dip 255.255.255.255 dip:10.0.0.254
Behaviour with other Router systems:
eth0:192.168.1.1 eth1:10.0.0.1 10.0.0.254
DHCP-Client ------------- Centos as Router / OpenWrt ------------------------ DHCP-Server
sip 0.0.0.0 ---> relayed with ------> sip: 10.0.0.1
dip 255.255.255.255 dip:10.0.0.254
Tested in a virtual environment (Hyper-V)
Screenshots of Wireshark traces could be supplied if needed.
Question is: Unicast from Relay to DHCP by default IP of DHCP-side interface or client-side interface?
I found amongst others the following sources stating that default should be DHCP-sided interface:
1. https://docs.commscope.com/bundle/fastiron-08030-l3guide/page/GUID-44165432-627D-48C8-87BF-8D304FEA253C.html
2. https://documentation.nokia.com/srlinux/23-3/books/interfaces/dhcp-relay.html
2. states that:
"...The DHCP relay agent relays the DHCP Discover message toward the DHCP server (unicast). If configured to do so, information is added for the circuit ID and remote ID sub-options in DHCP option 82. The relayed packet is unicast toward the DHCP servers with the following values:
SIP = outgoing interface IP address by default. If the source-address is configured, the relayed packet instead has SIP = configured source-address..."
Reference to the relevant RFC and in case for dhcrelay daemons option for "configured source-address" would be nice.
kind regards
Andreas, Munich