So the relay agent appears to have an internal IP that is part of the subnet. The relay agent is also on the router. I think it can also be on the switch, which would support my theory that the DHCP agent is strictly behind the gateway.

The DHCP relay agent receives DHCP Discover and Request messages broadcasted by the PC, and unicasts them directly to the DHCP server.

Lots of sources like this (cf. https://www.netmanias.com/en/post/techdocs/6000/dhcp-network-protocol/understanding-dhcp-relay-agents) talk about the relay agent as if it is in front of the gateway, or is used instead of the gateway.

As far as I understand it, the relay agent detects packets with source IPs, replaces them with the source IP of the relay agent and destination IP with the DHCP server and then passes it to the egress queue on the gateway. Because the gateway and the host should be on the same subnet (unlike in figure 2), the gateway can keep the source IP of the relay agent unchanged and add its MAC address. When the DHCP sever sends back the offer to the relay IP it should be picked up by the gateway as it is on the same subnet. I have no idea why figure 2 shows a changing of the source IP to that of the gateway's when it is not needed as all gateways in the stub domain use RFC 1918 addresses and there is hence no NAT.

Can anyone confirm this, in case I have any misperceptions?

  • I think you’re right. I don’t see any reason the IP address is being changed. It could just be a bad diagram. – Appleoddity Nov 9 '18 at 5:14
  • Seems like an interesting experiment to do with wireshark – Ricardo S. Nov 9 '18 at 7:55

why figure 2 shows a changing of the source IP to that of the gateway's

Figure 2 actually changes the source IP to that of the relay agent's, which just coincidentally happens to be a gateway as well.

And what's being done by the relay agent is not IP-layer NAT, but application-layer proxying. The job of a DHCP relay agent isn't to simply forward packets at IP level (like routers would), but to actually receive and process them and then generate new ones towards the other side.

(For that matter, DHCP in general is completely independent from IP routing/gatewaying. Any device attached to the subnet can act as the DHCP server or a relay agent.)

So because the two packets (original and proxied) are completely independent, and because the depicted relay agent is, indeed, a gateway with multiple interfaces, different algorithms are used to select the IP 'Source address' field than the DHCP 'Relay agent' field.

The DHCP 'Relay agent' field is always an address belonging to the interface which received the original 1a discover or 3a request. This allows a single device to act as a relay agent for multiple subnets at once – each local interface uses a different 'agent address'.

The IP 'Source address' field, however, doesn't care about DHCP. As far as the IP stack is concerned, 1b or 3b is a new UDP datagram that the relay agent wants to send. So after the route is decided, the IP source-address-selection algorithm usually picks an address belonging to the outgoing interface. It's as good as any.

(For IPv4 it's quite possibly implementation-dependent too. But you're correct that either address would work, as long as the DHCP server knows where to deliver the reply.)

  • 1
    So, the uplink IP is just a random source IP that is used by the relay and it doesn't matter what it is because the DHCP server is always going to use the helper address in the payload regardless to send back to – Lewis Kelsey Nov 9 '18 at 14:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.