Why are DHCP Offer and Ack broadcasted?

Bruce picture Bruce · May 17, 2012 · Viewed 29.6k times · Source

Why can't the server use the destination IP address of 0.0.0.0 as is used in source IP of DHCP Discover and Request? It can use the MAC address of the client learnt from DHCP Discover and Request to direct the frame to the appropriate client machine.

Answer

Avio picture Avio · May 25, 2012

The unicast or broadcast choice is specified in the DHCP RFC 2131:

If the 'giaddr' field in a DHCP message from a client is non-zero, the server sends any return messages to the 'DHCP server' port on the BOOTP relay agent whose address appears in 'giaddr'. If the 'giaddr' field is zero and the 'ciaddr' field is nonzero, then the server unicasts DHCPOFFER and DHCPACK messages to the address in 'ciaddr'. If 'giaddr' is zero and 'ciaddr' is zero, and the broadcast bit is set, then the server broadcasts DHCPOFFER and DHCPACK messages to 0xffffffff. If the broadcast bit is not set and 'giaddr' is zero and 'ciaddr' is zero, then the server unicasts DHCPOFFER and DHCPACK messages to the client's hardware address and 'yiaddr' address. In all cases, when 'giaddr' is zero, the server broadcasts any DHCPNAK messages to 0xffffffff.

with ciaddr and giaddr being:

ciaddr        4  Client IP address; only filled in if client is in BOUND, RENEW or REBINDING state and can respond to ARP requests.
giaddr        4  Relay agent IP address, used in booting via a relay agent.

So the DHCP server chooses to broadcast or not accordingly to the current state of the client (mainly if it has already a IP address or not) and accordingly to the sender of the message, if it's a relay agent or just a client.

Unicast DHCPOFFER

In this case, my DCHP server chose to unicast the DHCPOFFER because my machine already had a IP address and I don't have a relay agent in my LAN.

EDIT:

And nobody can use the IP address 0.0.0.0 as a destination address. As specified in the IPv4 RFC 5735:

0.0.0.0/8 - Addresses in this block refer to source hosts on "this" network. Address 0.0.0.0/32 may be used as a source address for this host on this network; other addresses within 0.0.0.0/8 may be used to refer to specified hosts on this network ([RFC1122], Section 3.2.1.3).