online posts 16
wireshark 101

task 4.2 · chapter 4 of 8: dhcp · 15 min

The relay

objective

Capture both sides of r1 at once and watch it relay DHCP: a broadcast on the home network becomes an ordinary packet to a server two hops away, with r1’s address written inside.

you edit, in the labanswers/4.2.yml

open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter

given
Capturemake capture AT=sw1:eth1,r1:eth2 NAME=4.2 X=dhcp
r1's configclick r1 on the Topology tab, then show running-config interface GigabitEthernet1
Your answersanswers/4.2.yml
new to this? step by stepbeginner
  1. make capture AT=sw1:eth1,r1:eth2 NAME=4.2 X=dhcp, open it, filter dhcp, add an Interface name column.
  2. Compare the Discover on sw1:eth1 with the copy on r1:eth2: their IP destinations.
  3. Challenge: the Relay agent IP address in r1’s copy, and the Offer’s source on sw1:eth1.
  4. Fill in answers/4.2.yml, then make check T=4.2.

more in meet the lab

1 explain

Broadcasts stop at the router. DHCP needs to get past.

The problem

The laptop’s Discover goes to 255.255.255.255: everyone on this network. Routers don’t forward broadcasts (that’s the point of a router, from Networking 101’s lesson on broadcast domains). So a DHCP server has to be on the same network as every client.

Real networks don’t work like that. A company with fifty offices has one or two DHCP servers in a data center, not fifty. What makes that possible is the DHCP relay.

How a relay works

The router on the client’s network listens for DHCP broadcasts, and passes each one on to a server it’s been told about, as an ordinary unicast packet that can be routed anywhere. On Cisco-style routers, CapeOS included, one line on the client-facing port does it:

interface GigabitEthernet1
 ip address 192.168.1.1 255.255.255.0
 ip helper-address 192.168.2.53

On the way, the router writes its own address on that port into the message’s Relay agent IP address field (called giaddr in the DHCP standard, for gateway IP address). That’s how the server knows which network the client is on, and so which pool to give it an address from: the server can’t tell from the packet’s source, because the client has no address yet.

The server sends its answer back to the relay, and the relay passes it to the client on the home network.

in one sentence A DHCP relay turns the client’s broadcast into a unicast to the server, and writes its own address in giaddr so the server knows which network to serve.

2 show

Both sides of r1

Capturing sw1:eth1 (the home network side of r1) and r1:eth2 (the side towards r2) at once:

 6	sw1:eth1	0.0.0.0	255.255.255.255	DHCP Discover - Transaction ID 0x38985e54	0.0.0.0
 7	r1:eth2	192.168.1.1	192.168.2.53	DHCP Discover - Transaction ID 0x38985e54	192.168.1.1
 8	r1:eth2	192.168.2.53	192.168.1.1	DHCP Offer    - Transaction ID 0x38985e54	192.168.1.1
 9	sw1:eth1	192.168.1.1	192.168.1.175	DHCP Offer    - Transaction ID 0x38985e54	192.168.1.1

The columns are frame number, interface, IP source, IP destination, summary, and the Relay agent IP address. Same transaction ID throughout: it’s one conversation, carried in two hops.

3 follow along

Watch the Discover change

  1. Look at r1’s config first. On the Topology tab, click r1. In the r1 tab it opens:

    run in the r1 tab
    show running-config interface GigabitEthernet1
    

    Then go back to the VS Code tab for the capture.

  2. Capture both sides of r1 while the laptop asks for an address again:

    run in the terminal
    make capture AT=sw1:eth1,r1:eth2 NAME=4.2 X=dhcp
    
  3. Open /captures/4.2.pcapng, filter dhcp, and add the Interface name column (right-click it in a frame’s first details line › Apply as Column).

  4. Find the Discover on sw1:eth1 and its copy on r1:eth2. Compare their IP destinations.

  5. Fill in the follow-along lines:

    editanswers/4.2.ymlCtrl+P → 4.2.yml
    lan_dst: 255.255.255.255
    relay_dst: 192.168.2.53
    
4 challenge

What r1 wrote

  • giaddr: the Relay agent IP address in r1’s copy of the Discover, on r1:eth2;
  • offer_from: the IP source of the Offer the laptop received, on sw1:eth1.

Then think about this: why does the dns server, at 192.168.2.53, hand out addresses in 192.168.1.0/24, a network it isn’t on?

hint

Open r1’s copy of the Discover. The Relay agent IP address is a few lines into the DHCP layer.

show the solutionanswers/4.2.yml

or pull it into your lab: make solve T=4.2, then git diff --staged shows what changed

giaddr: 192.168.1.1
offer_from: 192.168.1.1

r1 wrote 192.168.1.1, its address on the home network, into the Discover. The dns server matched that to its range for 192.168.1.0/24 and offered an address from it. The laptop only ever talks to r1: the Offer reaches it from 192.168.1.1, even though option 54 names the real server.

If DHCP ever stops working on one network only, capture both sides of the relay. No copy on the server side means the router isn’t relaying (a missing ip helper-address, or the wrong port). A copy with no answer means the server has no range for that giaddr.

5 check: run it, then prove it

$ make check T=4.2

when it's right, you'll see

╭─ task 4.2 · the relay
│  ✓ captures/4.2.pcapng: taken on r1:eth2, sw1:eth1, 13 frames
│  ✓ where the laptop sent its Discover, on the home network (follow along): 255.255.255.255
│  ✓ where r1 sent that Discover on, towards r2 (follow along): 192.168.2.53
│  ✓ the relay agent address r1 wrote into it (challenge): 192.168.1.1
│  ✓ who the laptop got its Offer from, at the IP layer (challenge): 192.168.1.1
╰─ 4/4 checks passed  verified