Skip to content
Ask AI

DHCP Relay Configuration

Since DHCP uses broadcasting to send request messages during the IP address dynamic allocation process, it is suitable only for cases where the DHCP client and server are within the same subnet. When the DHCP server and client are not in the same subnet, the DHCP relay mechanism needs to be employed.

In the context of DHCP relay, the message exchange is depicted as shown in the diagram:

  1. The Client Sends DHCP Discovery Broadcast:

When a DHCP client is located within a subnet and needs to obtain an IP address and other configuration information, it broadcasts a DHCP Discovery message (DHCP Discover) to the broadcast address of the local network.

  1. Relay Agent Forwards DHCP Message:

The DHCP relay agent forwards the received DHCP Discovery message (along with any other relevant DHCP messages) to the DHCP server, encapsulating the original broadcast message.

  1. DHCP Server Response:

Upon receiving the forwarded DHCP Discovery message in a different subnet, the DHCP server assigns an IP address to the client and generates a DHCP Offer broadcast message (DHCP Offer) back to the relay agent.

  1. Relay Agent Forwards DHCP Offer:

The DHCP relay agent forwards the DHCP Offer message back to the original subnet, encapsulating the IP address and configuration information provided by the DHCP server.

  1. Client Requests and Acknowledges:

The DHCP client, upon receiving the DHCP Offer message, selects a server and sends a DHCP Request message (DHCP Request) to request the allocated IP address. This request message is also forwarded by the relay agent to the DHCP server.

  1. Server Acknowledgment and Response:

Upon receiving the DHCP Request message, the DHCP server sends a DHCP Acknowledgment message (DHCP Acknowledgment) back to the relay agent. Similarly, the relay agent forwards the acknowledgment message to the subnet where the client is located.

Through this process, DHCP relay allows DHCP clients and servers located in different subnets to communicate without requiring a DHCP server to be set up on each subnet. The relay agent acts as a bridge, forwarding DHCP messages between different subnets, enabling DHCP communication to span physical network boundaries.

By default, when a device receives a request message from a DHCP client and re-encapsulates it, a field called “option82” is appended to the message to record the client’s location information. The “Relay agent IP address” field is the IP address of the VLAN SVI interface where the client is located. DHCP servers that support parsing the option82 field can use the information carried within it to determine which IP address range to allocate to the client. If the DHCP server does not support parsing the option82 field, the determination can be made based on the “Relay agent IP address.”

However, in scenarios involving cluster networks, access devices are configured as distributed gateways with the same SVI interface address. In such cases, the “dhcp-agent address” command needs to be used to allocate a unique agent IP address to each device. This is done to enable DHCP servers, when sending response messages, to use this unique IP address as the destination address, allowing differentiation among different access devices.

OperationCommandDescription
Enter the system configuration viewconfigure terminal
Create a DHCP relay instance and enter the DHCP relay viewdhcp-relay relay-name {v4|v6}
Specify the VLAN to which the DHCP clients belong that require dynamic IP address allocationdown_link interface vlan vlan-id
Specify the interface through which the device is connected to the DHCP serverup_link interface interface-type interface-name
Specify the IP address of the DHCP serverserver_ip ip-address
Configure using the loopback interface as the relay agent IPloopback_interface loopback ID
Enable the option to not encapsulate the option82 field (if needed)no_option82
Configure the relay agent IP address (if needed)dhcp-agent address ip-address

Network requirements

  • Suppose User 1 and User 3 of a company belong to Department A, User 2 and User 4 belong to Department B, Device A acts as a DHCP relay, and Device B acts as a DHCP server. It is required to assign IP addresses between 10.1.2.2 and 10.1.2.100 to Department A and between 10.1.10.2 and 10.1.10.100 to Department B.
  • DNS server, gateway and other information are assigned by DHCP server.

Procedure

  1. Configuration of Device A

# Create VLAN 100 and configure the IP address

sonic(config)# vlan 100
sonic(config)# interface ethernet 1
sonic(config-if-1)# switchport access vlan 100
sonic(config)# interface ethernet 2
sonic(config-if-2)# switchport access vlan 100
sonic(config)# interface vlan 100
sonic(config-vlanif-100)# ip address 10.1.2.1/24

# Create VLAN 200 and configure the IP address

sonic(config)# vlan 200
sonic(config)# interface ethernet 3
sonic(config-if-3)# switchport access vlan 200
sonic(config)# interface ethernet 4
sonic(config-if-4)# switchport access vlan 200
sonic(config)# interface vlan 200
sonic(config-vlanif-200)# ip address 10.1.10.1/24

# Configure the IP address

sonic(config)# interface ethernet 5
sonic(config-if-5)# ip address 10.110.1.1/30
sonic(config)# interface loopback 0
sonic(config-if-lo0)# ip address 10.120.1.1/32

Enable DHCP relay function

sonic(config)# dhcp-relay test v4
sonic(config-dhcp-relay-test__v4)# down_link interface vlan 100
sonic(config-dhcp-relay-test__v4)# down_link interface vlan 200
sonic(config-dhcp-relay-test__v4)# up_link interface 5
sonic(config-dhcp-relay-test__v4)# server_ip 10.110.1.2
sonic(config-dhcp-relay-test__v4)# loopback_interface loopback 0
sonic(config-dhcp-relay-test__v4)# exit
  1. Configuration of Device B
sonic(config)# interface ethernet 1
sonic(config-if-1)# ip address 10.110.1.2/30
sonic(config-if-1)# dhcp select server

# Create DHCP address pool

sonic(config)# dhcp pool userA
sonic(config-dhcp-pool-userA)# network 10.1.2.1 255.255.255.0
sonic(config-dhcp-pool-userA)# address-pool 10.1.2.2 10.1.2.100
sonic(config-dhcp-pool-userA)# dns 8.8.8.8
sonic(config-dhcp-pool-userA)# exit
sonic(config)# dhcp pool userB
sonic(config-dhcp-pool-userB)# network 10.1.10.1 255.255.255.0
sonic(config-dhcp-pool-userB)# address-pool 10.1.10.2 10.1.10.100
sonic(config-dhcp-pool-userB)# dns 8.8.8.8
sonic(config-dhcp-pool-userB)# exit

Verify configuration

  1. Check the requested IP address on the PC.
C:\Users\test>ipconfig
Windows IP Configuration
Ethernet Adapters Ethernet:
Connect to a specific DNS suffix . . . . . . :
Local Link IPv6 Address. . . . . . . . . . . : fe80::a495:f96e:6573:c383%12
IPv4 address . . . . . . . . . . . . . . . . : 10.1.10.144
subnet mask . . . . . . . . . . . . . . . . .: 255.255.255.0
Default Gateway. . . . . . . . . . . . . . . : 10.1.10.1
  1. Use the commands show dhcp relay config and show dhcp pool info on Device A and Device B respectively to view the DHCP relay and DHCP server configuration.