When a device is configured as a DHCP client, it will send a a broadcast packet to discover DHCP servers on the network. Broadcast packets are not forwarded by routers by default, so if a DHCP server is in a different network than the DHCP client, it will not receive the request. Consider the following scenario:
The workstation on the left is configured as a DHCP client. R2 on the right is configured as a DHCP server. The workstation sends a DHCP discover packet, but it receives no request, since R1 doesn’t forward the packet to R2 (broadcast packets stay on the local subnet).
To rectify this, we can configure R1 to act as a DHCP relay agent and forward the request to the configured DHCP server. This is done by issuing the ip helper-address DHCP_SERVER_IP_ADDRESS command on its Gi0/0 interface. This command instructs the router to do the following:
- watch for DHCP messages on the interface
- when a DHCP packet arrives, set the packet’s source IP address to the IP address of Gi0/0
- change the destination IP address of the packet from 255.255.255.255 (the broadcast address) to the IP address of the DHCP server and send it to R2
- when the answer from the DHCP server is received, change the packet’s destination IP to 255.255.255.255 and send it out its Gi0/0 interface, so that the workstation (which does not have an IP address yet) can receive the answer.
To configure the interface Gi0/0 on R1 to forward DHCP packets, only a single command is needed:
R1(config-if)#ip helper-address 172.16.0.2
To make sure that the workstation indeed got its IP parameters, we can issue the ipconfig command:
C:\>ipconfig FastEthernet0 Connection:(default port) Link-local IPv6 Address.........: FE80::2E0:B0FF:FEB3:73E IP Address......................: 10.0.0.104 Subnet Mask.....................: 255.255.255.0 Default Gateway.................: 10.0.0.1