The assignment of addresses using DHCP requires a DHCP server. This can be a separate device, but is often a program or system service on a computer in the network. This server is started at the first or runs continuously. A network can be managed by multiple DHCP servers.
Communication with the server takes place via the Dynamic Host Configuration Protocol, which was defined in RFC 2131 and uses UDP ports 67 and 68, as decided by the Internet Assigned Numbers Authority.
How to configure a host?
If new devices join the network, they need an address to communicate with others devices.
- By sending a DHCPDISCOVER message to the so-called IP broadcast address 255.255.255.255 (UDP port 67), the new device informs the DHCP servers that it requires a configuration. This message uses the sender 0.0.0.0 (UDP port broadcast 68), because the device does not have any IP address, and transmits the MAC address of the requesting device.
- All available DHCP servers respond with a DHCPOFFER message, submitting an offer to the requesting device, that may contain the IP address as well as other configuration details, such as the so-called lease-time (time the offered address can be used). This message is also broadcasted from their UDP port 67 to the 255.255.255.255 (UDP port 68).
- The requesting device selects one from the incoming bids. This can for example be the first offer, or one which is particularly suitable.
- The device calls for the selected configuration from the appropriate server. Therefore a DHCPREQUEST message is sent to all, in addition to the configuration data that identifies the target server. All other DHCP server that message notice this as rejection of their offer.
- The called DHCP server confirms the assignment with DHCPACK. Can this allocation be not provided (i.e. it has been given away meanwhile), the DHCP server rejects with DHCPNACK. Afterwards the requesting device can restart with a new DHCPDISCOVER request.
- The device may also consider asking the offered address itself, to check, that the offered address is indeed free. If an device responded from the offered address, the address is already in use. It can be rejected with DHCPDECLINE. fterwards the requesting device can restart with a new DHCPDISCOVER request.
The following commands are defined:
- DHCPDISCOVER (client->server): Requesting configuration data from an joining device.
- DHCPOFFER (server->client): Offers from DHCP servers in response to DHCPDISCOVER with configuration information.
- DHCPREQUEST (client->server): request to assign a selected configuration from the set supplied by DHCPOFFER. All other offers are rejected with this request.
- DHCPACK (server->client): Confirmation of the allocation.
- DHCPNACK (server->client): Rejection of allocation. The client can send a new DHCPDISCOVER.
- DHCPDECLINE (client->server): The client rejects from an IP address, since it is already being used. He can send a new DHCPDISCOVER.
- DHCPRELEASE (client->server): The client releases its configuration. His address is therefore available to others.
DHCP is particularly useful if the participants of the network change consistently or one does not want to deal with the network configuration.
It is also possible with the Dynamic Host Configuration Protocol to assign IP devices stable addresses. Therefore DHCP servers are configured to supply given MAC addresses every time with the same IP address. This IP address is reserved and will therefore only be offered to this MAC address.
With exception of the explitely assigned IP addresses the IP addresses of participants might change. Hence it is in general required to address the devices with their name.
The opposite of DHCP is to assign a fixed address to every network node. Since each device has permanently the same address, the boot order of the nodes is not important. No central entity is required to already run. In addition, the devices can also be addressed by means of their known safe IP address. This approach works however only for networks of manageable sizes with stable structures, because a duplicate IP address, has to be avoided.
The primary benefit of DHCP is the automatic configuration of all network partipants, once set up.