Configuration Guide
IP Service Configuration
DHCP Relay Configuration
10 min
introduction introduction 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 explanation of principles explanation of principles in the context of dhcp relay, the message exchange is depicted as shown in the diagram 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 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 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 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 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 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 adding option82 adding option82 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 dhcp relay configuration dhcp relay configuration operation command description enter the system configuration view configure terminal create a dhcp relay instance and enter the dhcp relay view dhcp relay relay name {v4|v6} specify the vlan to which the dhcp clients belong that require dynamic ip address allocation down link interface vlan vlan id specify the interface through which the device is connected to the dhcp server up link interface interface type interface name specify the ip address of the dhcp server server ip ip address configure using the loopback interface as the relay agent ip loopback 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 configuration example configuration example network requirements 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 procedure 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 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 verify configuration 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 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
