Cisco IOS DHCP Relay Agent

DHCP is often used for hosts to automatically assign IP addresses and uses 4 different packets to do so. Since a host doesn’t have an IP address to start with, we use broadcast messages on the network that hopefully end up at a DHCP server.




The problem with broadcast is that this means that the DHCP server has to be in the same broadcast domain since routers do not forward broadcast packets. Take a look at the following picture:

dhcp relay agent topology

On the left side, we have a client (H1), in the middle, a router (R1), and on the right side is our DHCP server. The client wants to get an IP address through DHCP and will broadcast a DHCP discover message. The router, doing its job, will not forward broadcast traffic, so the DHCP discover will never reach the DHCP server.

So how can we solve this? We have to use the DHCP Relay Agent feature. In short, the router will forward DHCP requests from the client to the DHCP server, when the DHCP server responds, it will forward the messages back to the client.

Let me describe this process in detail, step-by-step to you:

dhcp relay discover

The first thing that happens is that our client will broadcast a DHCP discover message, the router will receive this message since its in the same broadcast domain as the client. Here’s what happens next:

dhcp relay discover unicast

The router receives the DHCP discover message on its FastEthernet 0/0 interface and will normally just discard this packet. With the DHCP relay agent feature enabled, it will do something else. It will forward the DHCP discover message as a unicast packet and also insert a field called giaddr (Gateway IP Address) in the DHCP packet. It will insert the IP address 192.168.12.2 in this field since we received the DHCP discover on the FastEthernet 0/0 interface. This giaddr field is required by the DHCP server, or it won’t know from which pool it has to select an IP address. Also, the source IP address of this unicast packet will be 192.168.12.2. Let’s continue:

dhcp relay offer unicast

The DHCP server has received the DHCP discover message and in return, will send a DHCP offer message. This will be sent as a unicast packet to the router…

dhcp relay offer broadcast

The router, being a good relay, will forward the DHCP offer on its FastEthernet0/0 interface as a broadcast.

dhcp relay request broadcast

The client likes the content of the DHCP offer message and will create a DHCP request, which is broadcasted. The router hears this broadcast and will do this:

dhcp relay request unicast

Like the initial DHCP discover message, this DHCP request will be forwarded as a unicast packet. Once again, the giaddr field is inserted with IP address 192.168.12.2. The DHCP server receives the DHCP request and will process it…

dhcp relay dhcp ack

Last but not least, the DHCP server will send a DHCP ACK in response to the DHCP request. This is sent to the router using unicast, and our router will broadcast it on its FastEthernet 0/0 interface so the client receives it. The client now has an IP address.

Now you know how the DHCP relay agent works, let’s take a look at the configuration, shall we?

Configuration

I will be using three routers for this. The topology is the same as the one I just used for my explanation:

dhcp relay 3 routers example

Let’s start with the configuration of the interfaces:

H1(config)#interface FastEthernet 0/0
H1(config-if)#no shutdown
R1(config)#interface FastEthernet 0/0
R1(config-if)#no shutdown
R1(config-if)#ip address 192.168.12.2 255.255.255.0
R1(config)#interface FastEthernet 0/1
R1(config-if)#no shutdown
R1(config-if)#ip address 192.168.23.2 255.255.255.0
DHCP(config)#interface FastEthernet 0/0
DHCP(config-if)#no shutdown
DHCP(config-if)#ip address 192.168.23.3 255.255.255.0

Nothing special so far…let’s make a DHCP pool for the 192.168.12.0 /24 network. That’s where the client is at:

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now! Here is why:

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You’ve Ever Spent on Your Cisco Career!
  • Full Access to our 799 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)

576 Sign Ups in the last 30 days

satisfaction-guaranteed
100% Satisfaction Guaranteed!
You may cancel your monthly membership at any time.
No Questions Asked!

Tags: , ,


Forum Replies

  1. Hi rené, nice lab as usual, i have a question : don’t we have to exclude the ip address 192.168.12.2 from the pool address defined on the DHCP router because it has already been taken by the fastethernet 0/0 of the middle router, in order to prevent address conflict when assigning an ip address to the client router ??

    Thanks in advance.

  2. Hi Mohamed,

    Good question. If you try this with a few clients you’ll see that the DHCP server won’t give a lease for 192.168.12.2 since it’s already in use. However, it is nicer to configure some excludes for the IP addresses that have been configured statically.

    Rene

  3. There is absolutely no better place on the internet to study CISCO related materials than here. I am in Ghana, how do I purchase your books.

  4. Thanks for your kind words :slight_smile: The e-books are available through Clickbank and the hardcopies through Amazon.com, you can use a creditcard or paypal. If those are not accepted then we can always look for another online payment method that you can use…

  5. Hi rené, i have another question: How can we use DHCP Relay when we have multiple subinterfaces for multiple VLANs on the fastethernet 0/0 ( ie: fastethernet 0/0.1, 0/0.2 and so on) of the middle router knowing that each VLAN has its own addressing scheme ??

    Mohamed

66 more replies! Ask a question or join the discussion by visiting our Community Forum