Sub topic 4
Static Addresses Versus DHCP
This chapter covers the trade-offs between static and DHCP addressing for a server. It also covers the options in between, such as DHCP reservations, and the failure modes of each. It assumes you can read ip address output, know what a prefix length and a default gateway are, and can use sudo. The next chapters show how to write the configuration in Netplan and NetworkManager. This chapter helps you decide what to write.
What the two methods actually do
An interface needs four things to talk beyond its own subnet: an address with a prefix length, a default gateway, one or more DNS servers, and often a search domain. There are two ways to get them.
- Static configuration. An administrator writes the values into a configuration file on the server. The server uses them at every boot and never asks anyone else.
- DHCP (Dynamic Host Configuration Protocol). The server broadcasts a request when the interface comes up. A DHCP server on the network answers with an address and other options. The address is a lease, which is a loan for a fixed period. The client must renew the lease before it expires.
The DHCP exchange has four steps, often called DORA: Discover, Offer, Request, Acknowledge.
The server learns the gateway and DNS servers from the same reply as the address. With a static setup you must supply all of them yourself. Forgetting one is a common mistake. A static address with no gateway works on the local subnet and fails everywhere else. A static address with no DNS servers can reach IP addresses but not names.
Why servers usually need stable addresses
Other machines find a server by address or by a name that maps to an address. Many things depend on that mapping staying put:
- DNS records, such as an A record for
web01.example.com. - Firewall rules on other hosts that allow traffic from or to a specific address.
- Load balancer pools, monitoring targets, and backup jobs.
- Entries in
/etc/hosts, NFS exports, databasepg_hba.confrules, and similar files that list peers by address. - Your own SSH habits and any configuration management inventory.
If the address changes, each of these breaks, and the failures often look unrelated. A monitoring check goes red, a backup times out, and a client reports a connection refused. The root cause is a lease that expired and was given out again.
A stable address does not have to be configured on the server. It only has to stay the same. That leads to three common approaches.
Three ways to get a stable address
| Approach | Where the address is set | Server needs | Typical use |
|---|---|---|---|
| Static on the host | In the server's own configuration | Address, prefix, gateway, DNS | Servers that must boot with no DHCP service, infrastructure such as DNS or DHCP servers, isolated networks |
| DHCP reservation | On the DHCP server, which maps a MAC address (or client ID) to a fixed address | Nothing special, DHCP enabled | Fleets managed centrally, where the network team owns addressing |
| Plain dynamic DHCP | From a pool, with no promise of the same address | Nothing special | Laptops, desktops, short-lived test machines |
A DHCP reservation gives you the same address every time, so the server can stay configured for DHCP. The central record of addresses lives in one place. The cost is a dependency: the server needs the DHCP service during boot, and the reservation is tied to an identifier. If you replace the network card or clone a virtual machine, the MAC address may change and the reservation no longer matches.
A static address has the opposite trade-off. The server has no boot dependency on a DHCP service. The record of addresses is spread across every host, and nothing stops two hosts from being given the same address.
Trade-offs in detail
Boot and failure behavior
With DHCP, a server that boots while the DHCP service is down has no address. Services that bind to a specific address fail to start. Services that wait for network-online.target may wait through a timeout, which slows boot. A DHCP server or a DNS server that gets its own address from DHCP can create a circular dependency after a power outage, because each needs the other to start.
A static server comes up the same way every time, as long as the cable and switch work. This is the main reason core infrastructure uses static addresses.
Address conflicts
Two hosts with the same address cause intermittent failures. Traffic goes to whichever host answers the ARP request first, and that can change. A DHCP server tracks what it has handed out and avoids duplicates. It cannot know about a static address you chose inside its pool. To avoid this:
- Pick static addresses outside the DHCP pool. For example, if the pool is
192.168.1.100to192.168.1.200, use192.168.1.10to192.168.1.99for servers. - Record every static address in one place, such as an IPAM tool, a spreadsheet, or your configuration management repository.
- Check that an address is unused before assigning it.
The arping tool from the iputils package (or the arping package on Debian and Ubuntu) tests an address with ARP. In duplicate address detection mode, -D, it exits with status 0 if no one answered:
sudo arping -D -I enp1s0 -c 3 192.168.1.50
echo "exit status: $?"Exit status 0 means no reply was received, so the address looks free. A reply means someone already uses it. A silent host with a firewall that blocks ARP replies is rare, but a powered-off machine will also show as free. A free result is a good sign, not a guarantee.
Changing addresses later
Renumbering with DHCP reservations means editing one record on the DHCP server. Renumbering static servers means logging in to each one, or pushing the change with automation, and the change itself can cut off your session. For a fleet, that difference matters. For a handful of servers, it does not.
Security and control
Static configuration does not make a server more secure by itself. Anyone who can plug a device into the network can pick an unused static address as easily as ask for a lease. Control comes from the network: port security, 802.1X, and VLANs. DHCP does give you a central log of which MAC address held which address, which helps with auditing.
Cloud and virtual environments
In most cloud platforms, the instance uses DHCP, and the platform assigns the address from its own records. Setting a static address inside the guest operating system often breaks networking or conflicts with the platform. The stable address is set in the cloud console or API, for example an Elastic IP in AWS or a reserved IP in other providers. Check your provider's documentation before changing addressing inside a cloud image.
DHCP leases and what "dynamic" really means
A lease has a duration. The client tries to renew at about 50 percent of the lease time (called T1) and, if that fails, tries to rebind with any DHCP server at about 87.5 percent (T2). If the lease expires, the client must stop using the address.
In practice, a DHCP client that reconnects gets the same address back if the server still remembers it, so a "dynamic" address can stay unchanged for months. This is what makes it risky: the address looks stable until a long outage, a lease database reset, or a server rebuild changes it.
You can see the lease on a running server. Where the lease is stored depends on the tool that runs the DHCP client:
- With
systemd-networkd, usenetworkctl status enp1s0. It lists the address, gateway, DNS servers, and lease information. - With NetworkManager, use
nmcli device show enp1s0and look for theDHCP4.OPTIONlines, such asexpiryanddhcp_lease_time.
networkctl status enp1s0
nmcli -f DHCP4 device show enp1s0Run only the command that matches the tool managing the interface. The other will report that the interface is not managed or that the command is missing. The next chapter on tool selection explains how to tell which is which.
Mixed setups
You can combine methods on one interface.
- Static IPv4 with DHCP for IPv6, or the reverse. Each address family has its own method setting.
- Static address plus DHCP-provided DNS. Most tools let you take only some options from DHCP, but this mix is hard to reason about. When the address is static, set the DNS servers statically too, so the server does not depend on DHCP for anything.
- Multiple addresses on one interface. A server can hold a static address for management and a second one for a service. Both appear as separate
inetlines inip address.
If you keep DHCP enabled and also list a static address, the interface holds both. Many administrators are surprised when ip address shows two addresses after a "static" change. Turn DHCP off for the family you are configuring.
A decision checklist
Choose static addressing on the host when:
- The server provides DHCP, DNS, or other services the network needs to boot.
- The network has no DHCP service, or the server is in an isolated segment.
- You must be able to reach the server when central services are down.
- Policy or tooling requires the address to be visible in the server's own configuration.
Choose a DHCP reservation when:
- A network team already manages DHCP and wants a single source of truth.
- You manage many servers and renumbering is expected.
- The server is a virtual machine that is cloned often. Use a client identifier that you control instead of the MAC address.
Choose plain dynamic DHCP when:
- No other machine depends on this host's address.
- The machine is temporary or is a client rather than a server.
Common mistakes
- Choosing an address inside the DHCP pool. The DHCP server may later lease it to another machine and cause a conflict.
- Using the wrong prefix length. A
/24written as/16makes the server think distant hosts are local, so it sends ARP requests instead of using the gateway. A/24written where the real network is/23makes it use the gateway for hosts that are on the local link. - Leaving out the gateway or DNS servers. The address works locally, but nothing beyond the subnet or any name lookup does.
- Leaving DHCP on. The interface gets a second, dynamic address and may add a second default route.
- Using the address of the gateway, the broadcast address, or the network address. For
192.168.1.0/24, avoid192.168.1.0,192.168.1.255, and the router's own address. - Not recording the assignment. A static address that exists only in one server's file will be handed out again by mistake.
Exercise
Your DHCP pool is 192.168.10.100 to 192.168.10.250 on 192.168.10.0/24, and the router is 192.168.10.1. You must give a new database server a fixed address, and the network team says the DHCP service is sometimes taken down for maintenance for up to an hour. Which approach do you choose, which address range do you pick from, and why?
Show answer
Use a static address configured on the host, because a DHCP reservation would leave the server with no address if it reboots during DHCP maintenance. Pick an address outside the pool and not the router's, such as 192.168.10.20, and confirm it is unused with arping -D before assigning it. Record it in your address inventory and set the gateway (192.168.10.1) and DNS servers statically too.
Exercise
After you configure a "static" address on a server that previously used DHCP, ip -br address show lists two IPv4 addresses on the interface. What is the most likely cause, and what do you change?
Show answer
DHCP is still enabled for IPv4 on that interface, so the client obtained a lease in addition to the static address. Turn off DHCP for IPv4 in the configuration (dhcp4: false in Netplan, or ipv4.method manual in NetworkManager) and reapply it. Check with ip -br address show that only the static address remains.