DHCP: How Devices Get Addresses, and Why Servers Get Static IPs
Every device on a network needs an IP address, netmask, gateway, and DNS servers to function properly. Manually configuring these settings for every device is impractical, so Dynamic Host Configuration Protocol (DHCP) automatically assigns them.
sequenceDiagram participant C as New Device participant S as DHCP Server C->>S: DISCOVER broadcast S->>C: OFFER an address C->>S: REQUEST that address S->>C: ACK lease granted
Overview of DHCP
The problem: Every device must have specific network configuration details—IP addresses, netmasks, gateways, and DNS servers—to communicate effectively. However, manually entering these into each device would be cumbersome. DHCP solves this by dynamically assigning IP addresses to devices on the network.
How DHCP Works: DORA in 4 Steps
- DISCOVER: A new device broadcasts a message asking if anyone is willing to hand out an address.
- OFFER: The server responds with an offer, suggesting an available IP address (e.g.,
192.168.1.147). - REQUEST: The device confirms it wants the offered address.
- ACK: The server acknowledges and assigns the address for a limited time period.
During this process, the device does not yet have an IP address, so it continues to broadcast its request until an offer is received.
Vocabulary
- Scope/Pool: This refers to the range of IP addresses that the DHCP server can assign. For example,
192.168.1.100to192.168.1.199. - Lease: Addresses are rented for a period of time (called a lease). Devices renew their leases halfway through the lease duration.
- Reservation: A specific IP address is reserved for a particular device based on its MAC address. This ensures that the device always gets the same IP address, providing both central control and predictability.
- Options: DHCP can also deliver additional configuration information such as gateway addresses, DNS servers, NTP servers, etc., in what are called options.
Why Servers Get Static IPs
While most devices on a network use DHCP to get their IP addresses, core infrastructure like the NAS (Network Attached Storage), DNS server, and hypervisors should have genuinely static IP addresses. These devices need to be accessible even if the DHCP server is down or unavailable.
Key Differences:
- Static IP: Configured directly on the device and remains constant regardless of network changes.
- Reservation: A MAC address-based reservation ensures that a specific device always gets the same IP address, providing stability.
In most home networks, it’s best to use reservations for devices like servers or critical infrastructure. If changing an IP address causes issues with other connected devices, it likely means that device should be reserved rather than dynamically assigned.
Classic Failure Modes
- Two DHCP Servers on One Network: Plugging in a second router LAN-side can cause two DHCP servers to compete, leading to conflicts.
- Pool Exhaustion: If the pool of available IP addresses is exhausted, new devices will not be able to join the network.
- Self-Assigned Address (169.254.x.x): When a device cannot reach the DHCP server, it may assign itself an address from the
169.254range, indicating that DHCP is unreachable.
Understanding these concepts and potential issues will help in maintaining a stable and reliable network setup.