Concepts / Addresses and clocks

Addresses and clocks

DHCP relay

Also called ip helper-address, helper address, relay agent, giaddr, gateway IP address, option 82, relay agent information, circuit ID, dhcrelay

A router that passes DHCP broadcasts on to a server on another network, so one server can serve many.

A client's Discover is a broadcast, which stops at the router. A relay (ip helper-address on IOS, set on the client-facing interface) sends it on by unicast to the server, with its own address on the client's network as the giaddr. The server picks the pool whose subnet holds the giaddr and replies to the relay, which hands the answer to the client; the server needs a route back. With option 82 the relay also says where the request came from: a circuit ID for the port, a remote ID for itself.

One request, two addresses on the router
One request, two addresses on the router

The relay sends from the card facing the server, and the note inside names the card facing the client, which is where the reply goes. From the DHCP relaying: one address server for every hall lab.

How a DHCP relay works, step by step

A DHCP client starts with no address and broadcasts its Discover to 255.255.255.255 (RFC 2131). Routers do not forward broadcasts, so a server hears only clients on its own segment. A relay agent (RFC 1542) carries the exchange across the router, so one server can serve many networks. In the DHCP relaying lab one server addressServer 10.0.3.10 serves two halls: mainHall 10.0.1.0/24 and eastHall 10.0.2.0/24, with venueRouter relaying, its address 10.0.1.2 and 10.0.2.2 in each hall.

  1. The client broadcasts a Discover from 0.0.0.0 port 68 to 255.255.255.255 port 67. The router receives it because it is on the link, but does not forward the broadcast.
  2. The relay rewrites and unicasts it to the server on port 67, setting giaddr (the gateway IP address field) to its own address on the client's network, here 10.0.2.2, and counting hops.
  3. The server picks the pool by giaddr. 10.0.2.2 falls in 10.0.2.0/24, so it leases from the east hall's pool and sends the east hall's gateway. Without a relay it would use the subnet of the receiving card.
  4. The reply goes back to the giaddr, not the client, which has no address yet. The server needs a route back to 10.0.2.2 through venueRouter.
  5. The relay delivers it to the client, and the Request and ACK follow the same path. Later renewals need no relay: the client now has an address and the server's, so it unicasts directly.

With option 82 the relay also records where the request came from, covered below.

What it looks like on a Linux machine

venueRouter runs ISC dhcrelay, listening for clients on each hall's card (-id) and talking upstream on the server's (-iu):

$ dhcrelay -4 -id mainHall -id eastHall -iu serverRoom 10.0.3.10

A capture on the relay shows the four legs. tcpdump labels DHCP BOOTP/DHCP, with Request meaning toward a server and Reply from one:

$ tcpdump -nni any port 67
mainHall B   IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from ...
serverRoom Out IP 10.0.3.2.67 > 10.0.3.10.67: BOOTP/DHCP, Request from ...
serverRoom In  IP 10.0.3.10.67 > 10.0.1.2.67: BOOTP/DHCP, Reply, length 300
mainHall Out IP 10.0.1.2.67 > 10.0.1.10.68: BOOTP/DHCP, Reply, length 300

On the server, -v shows what the relay wrote in a request from the east hall:

10.0.3.2.67 > 10.0.3.10.67: BOOTP/DHCP, Request from ..., hops 1, ...
	  Gateway-IP 10.0.2.2

The client's lease comes from a server on a network it is not on:

$ dhcp-renew
udhcpc eth0: bound: address 10.0.2.10/24, gateway 10.0.2.2, DNS server none, lease 3600s, from DHCP server 10.0.3.10

The server reaches the relay's east hall address through the router, which is why its offers arrive:

$ ip route get 10.0.2.2
10.0.2.2 via 10.0.3.2 dev eth0 src 10.0.3.10

What goes wrong, and how you see it

One network gets nothing, another is fine. If the relay is started without a client-facing card for a hall, that hall's broadcasts reach the router and stop there. A capture shows 0.0.0.0.68 > 255.255.255.255.67 arriving and nothing going on to 10.0.3.10.67. The fix is a -id for each client network (one helper address per client-facing interface).

Requests arrive, offers never come back. The server logs an offer, the client never sees it. The reply goes to the giaddr, so the server needs a route to every relayed network; ip route get 10.0.2.2 answering Network unreachable is the cause. Add the route back.

No address range available. The server's log reads no address range available for DHCP request via 10.0.2.2: it got the request but has no pool containing the giaddr. Add the missing pool.

Double option 82. A snooping switch and the router both add relay agent information; a server set to drop mismatches discards the request. The DHCP relaying lab walks the first two.

Questions people ask

What is giaddr? The gateway IP address field in the DHCP header. The relay writes its own address on the client's network into it; the server reads it to pick the right pool and to know where to send the reply.

What is a DHCP helper address? The Cisco name for the same thing: ip helper-address 10.0.3.10 on an interface turns that interface into a relay toward that server. On Linux it is dhcrelay.

What is option 82? Relay agent information: a circuit ID naming the port the request came in on and a remote ID naming the relay, so the server can assign and log by location. See DHCP.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab