Featured Posts

CCIE-Journals

CCIE-Journals
From Student to Engineer,a journey of discovery.

DHCP Relay

 Configuring & Verifying DHCP client and relay


Introduction



Dynamic Host Configuration Protocol (DHCP) is a network protocol used to assign IP addresses and other network configuration parameters dynamically to devices on a network. DHCP clients are devices that request an IP address and other configuration parameters from a DHCP server. DHCP relay agents are devices that help DHCP clients on one network segment communicate with DHCP servers on another network segment.

In this blog post, we will discuss DHCP relay agents and how they can be configured on Cisco devices. We will also provide a diagram showing a DHCP client communicating with a DHCP server outside of its subnet, and walk through the configuration and packet flow. Finally, we will use show commands to validate the DHCP output and IP address assignment on the client, router/gateway, and DHCP server.

What is a DHCP relay agent?

A DHCP relay agent is a device that receives DHCP broadcast messages from DHCP clients on one network segment and forwards them to a DHCP server on another network segment. The DHCP relay agent adds its own IP address to the DHCP packet as the "giaddr" (gateway IP address) and then forwards the packet to the DHCP server.

DHCP relay agents are typically used in larger networks where multiple network segments are present, and DHCP servers are not located on the same subnet as the DHCP clients. By using a DHCP relay agent, DHCP clients can still obtain IP addresses and other configuration parameters even though the DHCP server is not located on the same subnet.

 Here in this picture:In a relay run, the baton is passed from one runner to the next until the team completes the race. Similarly, in a DHCP relay agent, DHCP messages are passed from one network segment to another until a client obtains an IP address.



Below is a diagram showing a DHCP client communicating with a DHCP server outside of its subnet, with a DHCP relay agent in between:
 


 

Configuration and packet flow


Let's walk through the configuration and packet flow for the diagram above.

                                                Switch Configuration:

There is no specific configuration required on the switch for DHCP relay.

                                                Router Configuration:

    a. Configure the router interfaces connected to the switch and the DHCP server:

interface GigabitEthernet0/0
ip address 192.168.1.254 255.255.255.0
!
interface GigabitEthernet0/1
ip address 10.10.10.1 255.255.255.0

    b. Enable DHCP relay agent on the router's interface connected to the switch:
 
interface GigabitEthernet0/0
ip helper-address 10.10.10.2

This command tells the router to forward DHCP requests received on this interface to the DHCP server with IP address 10.10.10.2.

                                                DHCP Server Configuration:

        a. Configure the DHCP pool and the IP address range for the subnet:
 
ip dhcp pool dhcp_pool
network 10.10.10.0 255.255.255.0
default-router 10.10.10.1
dns-server 8.8.8.8
lease 7

        b. Enable DHCP service on the server's interface connected to the subnet:

interface GigabitEthernet0/0
ip address 10.10.10.2 255.255.255.0
no shutdown
service dhcp

                                                Client Configuration:

Set the client to use DHCP to obtain an IP address. This is typically done through the client's network settings or by running the ipconfig /renew command on Windows or dhclient command on Linux.

That's it! With these configurations in place, the DHCP client should be able to obtain an IP address from the DHCP server, even though they are in different subnets.


Packet flow


  • The DHCP client sends a broadcast DHCP discover message to obtain an IP address.

  • The DHCP relay agent receives the broadcast message and adds its own IP address (10.10.10.1) as the giaddr before forwarding the message to the DHCP server (10.10.10.2).

  • The DHCP server receives the DHCP discover message, allocates an IP address and other configuration parameters, and sends a DHCP offer message to the DHCP relay agent.

  • The DHCP relay agent receives the DHCP offer message, replaces its own IP address (10.10.10.1) with the client's IP address (192.168.1.1) as the giaddr, and forwards the message to the DHCP client.

  • The DHCP client receives the DHCP offer message and sends a DHCP request message to confirm the allocation of the offered IP address.

  • The DHCP relay agent receives the DHCP request message, replaces the giaddr with the client's IP address (192.168.1.1), and forwards the message to the DHCP server.

  • The DHCP server receives the DHCP request message, acknowledges the allocation of the IP address, and sends a DHCP acknowledgement message to the DHCP relay agent.

  • The DHCP relay agent receives the DHCP acknowledgement message, replaces its own IP address (10.10.10.1) with the client's IP address (192.168.1.1), and forwards the message to the DHCP client.

  • The DHCP client receives the DHCP acknowledgement message and configures its IP address and other configuration parameters.

Validating the DHCP output and IP address assignment


To validate the DHCP output and IP address assignment, we can use the following show commands:

  • show ip dhcp binding: displays a list of all IP addresses assigned by the DHCP server and their lease expiration times.

  • show ip dhcp pool: displays information about the DHCP address pool, including the range of IP addresses, the subnet mask, and the default gateway.

  • show ip dhcp server statistics: displays statistics about the number of DHCP requests received, DHCP offers sent, DHCP acknowledgements sent, and DHCP declines sent.

  • show ip interface brief: displays a summary of the IP address, status, and protocol information for all interfaces on the device.

  • show running-config interface <interface-name>: displays the configuration of the specified interface.


By using these show commands, we can verify that the DHCP client has received an IP address from the DHCP server and that the DHCP relay agent has correctly forwarded DHCP messages between the client and the server.

Conclusion

In this blog post, we have discussed DHCP relay agents and how they can be configured on Cisco devices. We have provided a diagram showing a DHCP client communicating with a DHCP server outside of its subnet, and walked through the configuration and packet flow. Finally, we have used show commands to validate the DHCP output and IP address assignment on the client, router/gateway, and DHCP server. By following these steps, you can configure and verify DHCP client and relay on your network.

0 comments:

Post a Comment