Sub topic 10
Relay agents: one server for many subnets
This chapter assumes you know the Discover, Offer, Request, Acknowledge (DORA) exchange, that DHCP clients start with a broadcast, and that routers do not forward broadcasts. It also assumes you can read an IPv4 subnet and a scope definition.
The problem: broadcasts stop at the router
A client with no address sends its Discover to 255.255.255.255. That packet reaches every host on the local subnet and goes no further, because a router does not forward limited broadcasts. If the DHCP server sits on another subnet, it never sees the Discover.
You have two options. You can run a DHCP server on every subnet, which means many servers to configure and keep consistent. Or you can run one central server and let a router on each subnet pass the DHCP messages along. The second option uses a relay agent, a device that receives a client's broadcast and forwards it as a unicast packet to a known DHCP server. This is also called a DHCP helper.
How a relay works
The relay is usually the router that is the default gateway for the client's subnet. You configure it with the IP address of the DHCP server. The relay then does the following:
- It receives the client's broadcast Discover on the client-facing interface.
- It writes the address of that interface into the giaddr field (gateway IP address) of the DHCP message.
- It sends the message as a unicast packet to the server, using UDP port 67 as the destination.
- The server reads giaddr, picks the scope that matches that subnet, and replies by unicast to the giaddr address.
- The relay delivers the reply to the client on the local subnet, as a broadcast or as a unicast to the client's hardware address.
The relay repeats this for the Request and Acknowledge messages. The server never needs an interface on the client's subnet.
Why giaddr selects the scope
The server has no other way to know where the client is. The source address of the forwarded packet is the relay's address on the server-facing side, which may differ from the client subnet. The giaddr value is the key. The server matches it against its scopes and offers an address from the one whose subnet contains giaddr.
For example, a server with these scopes answers a relayed request with giaddr 10.1.20.1 from the second scope:
| Scope | Range | Gateway option |
|---|---|---|
| Servers | 10.1.10.100 to 10.1.10.200 | 10.1.10.1 |
| Staff | 10.1.20.100 to 10.1.20.200 | 10.1.20.1 |
If no scope contains the giaddr subnet, the server stays silent. The client sees no Offer.
Configuring a relay
On a Linux router you can use the ISC relay:
sudo dhcrelay -i eth1 10.1.1.10Here eth1 is the interface facing the clients, and 10.1.1.10 is the DHCP server. On many routers the same job is one command on the client-facing interface, often named ip helper-address.
The server must also have a route back to the relay's address, and any firewall must allow UDP 67 between them.
Common errors
- No scope for the subnet. The server receives the request but has no scope matching giaddr, so it ignores it.
- Missing route. The server cannot reach giaddr, so the Offer is lost.
- Relay configured on the wrong interface. giaddr then holds an address from the wrong subnet, and clients receive addresses that do not match their network.
- Firewall blocking UDP 67 between the relay and the server.
To check, capture on the server and look at the giaddr field in the Discover:
sudo tcpdump -n -i eth0 -vv 'udp and (port 67 or port 68)'Exercise
A client on 10.1.30.0/24 sends a Discover. The relay on that subnet has the address 10.1.30.1 and the central server is 10.1.1.10. What value does the relay put in giaddr, and what does the server do with it?
Show answer
The relay puts 10.1.30.1 in giaddr, the address of its client-facing interface. The server finds the scope that contains 10.1.30.1, which is the 10.1.30.0/24 scope, and offers an address from it. It sends the Offer by unicast to 10.1.30.1, and the relay delivers it to the client.
Exercise
Clients on a new subnet get no address, although the relay is configured and the server works for other subnets. Name two likely causes.
Show answer
The server may have no scope for the new subnet, so it ignores requests whose giaddr matches nothing. Alternatively, the server may have no route back to the relay address, or a firewall may block UDP 67.