When a computer connects to the network, it must find
its IP address, router, name server and so forth. DHCP tells it.
Once a system makes a physical or radio connection
to the network, it sends a message to the limited
broadcast address 255.255.255.255 to find out who it is.
Exchange continues from there, using real addresses as soon as possible.
DHCP messages use the UDP transport protocol, which we haven't
talked about yet, but here's how it encapsulates:
DHCP Message
UDP Header
UDP Payload
IP Header
IP Payload (ICMP message)
Frame Header
Frame Payload (IP datagram)
The Ethernet frame type is 0800 hex for Internet.
The Type field in the IP header contains 17 for UDP.
The UDP header does not have a type, but uses DHCP ports, 67 or 68,
depending on the direction, client-to-server or server-to-client.
Message Format.
The protocol evolved from the earlier BOOTP protocol.
In the good old days, things like IP addresses were configured
by hand on each of the very few machines that needed one.
Then we invented the PC, and the administrators typing fingers
got tired, so we needed an automatic solution.
A PC sitting on a desk or table needs its network configuration
when it starts up, hence the name BOOTP.
As portable devices and wireless evolved, the protocol needed to
do more, and needed to do it at any network connection, which need
not be at boot time.
The message format was not changed, but some of its fields
are obsolete.
DHCP message format.
Operation
Hdwr Type
Hdwr len
Hops
Transaction ID
Seconds Elapsed
Flags
Client IP Address
Your IP Address
Server IP Address
Gateway IP Address
Client Hdwr Address (16 bytes)
Server host name (64 bytes)
Boot file name (128 bytes)
Options (variable)
The Operation is simply a 1 or 2 for client-to-server or
server-to-client. The real operation is defined in the options
section.
Hardware type and length: Usually Ethernet, with length 6.
Hops is part of relaying, see later.
Transaction Identifier is a random number used to associate
requests with responses, so when you get an answer, you know what
question it is to.
The server and boot file names are for remote booting.
If provided, the client boots the indicated file from the indicated
server. Not used much anymore.
Client IP: Client's current IP address, if known, or zero.
Your IP: Address being provided by a server to a client.
Set to zero in other contexts.
Server IP: The IP of the DHCP server, so client can send
future message directly.
Gateway IP: The address of a DHCP relay, discussed later.
Options: Where the action is
This is a string of key/value pairs. (The option keys are given
by code number, not string names. Values often are strings.)
As the protocol evolved, rather than adding more fields to the
message, they just added more option keys.
The most important is DHCP Message Type (option 53), which
is what tells what the message is really for, not the
the Operation from the main fields.
Other options request or receive client host name, DNS server
address, router information, and pretty much anything else you
want a connecting host to know.
Operation
Booting machine broadcasts a DHCPDISCOVER request to 255.255.255.255:67.
Server responds with a DHCPOFFER to 255.255.255.255:68.
Contains a “Your IP” address, and other parameters in the
options section.
Note: Even though this is sent to a broadcast IP address, since the
client doesn't yet know its IP address, the hardware packet is usually
directed to the requestors MAC address so as not to create more
broadcast LAN traffic.
Client accepts by sending a DHCPREQUEST echoing the assignment.
Server responds with DHCPACK (okay) or DHCPNAK (no).
There wouldn't normally be much reason to say no, but in a busy
network, with a lot going on, something might have changed since
the offer. The client would start again with a DHCPDISCOVER.
A client wishing to reuse a previous address starts with the
DHCPREQUEST, which the server may allow or not.
On shutdown, the host sends DHCPRELEASE to surrender its address.
Addresses are not given permanently; they are said to be “leased.”
When a client gets an address, the assignment expires after some
period specified by the server.
Clients typically ask for an extension when the period is about up
using a new DHCPREQUEST.
Leasing is used so the address can be reclaimed eventually, even if
the client is unable to DHCPRELEASE.
Address allocation.
In a business or school where only certain machines are allowed,
the DHCP server may assign a specific IP based on its MAC address.
Here, for instance, you get the same IP whenever you connect
the same machine.
If your machine isn't known, you don't get an address.
A public net, such as a coffee shop or a hotel, will assign IP
addresses randomly out of a specified range.
Apple is trying to break DHCP.
Apple has started using random numbers instead of true MAC addresses
for all networking functions. This is done to frustrate tracking.
But it breaks DHCP that assigns IPs by MAC, and can exhaust
random-assignment pools by getting a new IP on every connection.
For latter, just set a short lease time.
For the former, I'm reading that some of these will try the true
address if they can't get an address from the random one. (Don't
know if that info is new, old, or just wrong.)
DHCP Relay
Generally, packets bound to the limited broadcast address,
255.255.255.255 used for discovery,
are not forwarded by an IP router; they are limited
to one physical network.
Instead of putting a DHCP server on every segment, an organization
may put it on one, and set up DHCP relays on the the others.
These will accept and forward the DHCPDISCOVER to the true server.
The relay puts its own IP in the router address field to help the
DHCP server know what address to offer.
Conversation can generally continue from there without broadcast,
perhaps with the relay forwarding when needed.
The Hops field in the DHCP message tells how many times it's been
relayed, and can be dropped if the DHCP server thinks it is too large.
Purpose much like the IP TTL.
IP6 does not need DHCP for a host to find its address; neighbor
discovery and the fact the host can compute its own host number
takes care of that. It will use DHCP to find other parameters.