Sub topic 8
Scopes, exclusions and reservations on a server
This chapter assumes you know how a client gets its address through Discover, Offer, Request and Acknowledge, and that you understand IPv4 subnets, masks, gateways and DNS servers. Here you will see how a DHCP server decides which addresses it may hand out and how it treats special devices.
What a scope is
A scope is the server's configuration for one subnet. It holds the address range the server may lease, the subnet mask, the lease time, and the options (router, DNS server and so on) that go with the leases. Products use different names for this idea.
| Product | Term for a scope |
|---|---|
| Windows Server DHCP | Scope |
| ISC DHCP (`dhcpd`) | `subnet` block with a `range` or `pool` |
| dnsmasq | `dhcp-range` line |
| Kea | `subnet4` entry with `pools` |
A scope belongs to exactly one subnet. A server that serves three subnets has three scopes. When a request arrives, the server must pick the right scope. For a client on the same segment as the server, it uses the interface the request came in on. For a client behind a relay agent, it uses the relay's address, which the next chapters cover. If no scope matches, the server stays silent and the client falls back to its own behavior.
A scope has these parts:
- A network and mask, such as 192.168.1.0/24.
- A pool, which is the first and last address available for dynamic leases.
- A lease duration.
- Options that apply to every client in the scope.
- Exclusions and reservations, which are the subject of this chapter.
Dividing the address space
A /24 has 254 usable host addresses, but the pool rarely uses all of them. The rest is split into areas with different purposes.
This layout is a convention, not a protocol rule. DHCP itself says nothing about where infrastructure devices live. Choosing fixed areas makes the network easier to read. When you see 192.168.1.1 in a log, you know it is the router.
Exclusions
An exclusion is a block of addresses inside the pool range that the server must never lease. You need one when something else already uses those addresses. Typical cases are printers with manually configured addresses, a server that predates the DHCP deployment, or a block you want to keep free for a temporary project.
Without an exclusion, the server can lease an address that a static device already uses. Two hosts then claim the same IP and both lose connectivity at random. Servers try to prevent this with conflict detection. The server may send an ICMP echo to the address before offering it, and a client should run an ARP probe before using the address, sending a Decline if someone answers. These checks reduce the damage but are not a substitute for correct planning.
How you create an exclusion depends on the product:
- Windows Server has an explicit Exclusion Range setting under the scope.
- ISC DHCP and Kea have no exclusion object. You define two pools that leave the gap between them.
- dnsmasq works the same way. You write two
dhcp-rangelines, or you choose a range that avoids the static addresses.
A dnsmasq version of the layout above, with 150 to 159 excluded, looks like this:
dhcp-range=192.168.1.100,192.168.1.149,255.255.255.0,12h
dhcp-range=192.168.1.160,192.168.1.200,255.255.255.0,12hThe simplest rule is to keep all static addresses outside the pool. Then you rarely need exclusions at all.
Reservations
A reservation ties one address to one client identity. Whenever that client asks for an address, the server gives it the reserved one. The client still uses DHCP. It sends Discover and Request like any other client and receives the same options as the rest of the scope, such as the gateway and DNS servers.
Most servers identify the client by its MAC address. Some can use the client identifier (option 61) or a hostname instead. This matters because the identifier the client sends is not always the MAC.
A reservation differs from a static configuration on the device itself:
| Row | Static on the device | DHCP reservation |
|---|---|---|
| Where the address is set | On each device | On the server |
| Gateway or DNS change | Edit every device | Change the scope option once |
| Address visible in one place | No | Yes, in the server config |
| Works if the DHCP server is down | Yes | Only until the lease expires |
| Risk of duplicate addresses | High | Low, the server tracks it |
Reservations suit printers, cameras, network storage and any device that others reach by address. Routers, the DHCP server itself, and other devices needed to bring DHCP up should stay static. A server that depends on DHCP to start cannot reach the DHCP server if the lease source is missing.
Where the reserved address lives
You can place a reservation inside or outside the dynamic pool, but it must belong to the scope's subnet. Servers differ in the details. Windows requires the reserved address to be in the scope range, and it is removed from the free pool automatically. In dnsmasq and ISC DHCP the address may be outside the pool. The recommended habit is to place reservations outside the dynamic pool, as the diagram does with .50. That avoids accidental clashes and makes the pool size easy to calculate.
A working configuration
This dnsmasq configuration defines a pool, the options, and one reservation:
# /etc/dnsmasq.conf (DHCP part only)
interface=eth0
# Hand out 192.168.1.100-192.168.1.200 with a 12-hour lease
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,12h
# Option 3 (router) and option 6 (DNS server)
dhcp-option=option:router,192.168.1.1
dhcp-option=option:dns-server,192.168.1.1
# Reservation: this MAC address always gets the same IP
dhcp-host=aa:bb:cc:dd:ee:ff,192.168.1.50Reading it line by line:
interface=eth0limits dnsmasq to one interface, so it only answers on that segment.dhcp-rangeis the pool. The four fields are first address, last address, mask and lease time. It holds 101 addresses.- The two
dhcp-optionlines add options that every client in the scope receives. dhcp-hostis the reservation. Its address 192.168.1.50 is outside the pool, so no dynamic client can take it.
Check the syntax before restarting the service with dnsmasq --test. After clients connect, dnsmasq records its leases in a file, often /var/lib/misc/dnsmasq.leases. Each line holds the expiry time, MAC address, IP address and hostname.
Sizing the pool
The pool must hold more addresses than the number of devices that can be online during one lease period, plus some margin. Short leases return addresses to the pool faster, so a guest network with many short visits can use a smaller pool with a short lease. A long lease on a busy guest network can exhaust the pool even though few devices are present at any moment, because departed devices still hold their addresses until the leases expire.
You can compute the usable pool size from the plan. This script applies the exclusion and checks that every reservation is valid:
import ipaddress
ip = ipaddress.ip_address
network = ipaddress.ip_network("192.168.1.0/24")
pool = (ip("192.168.1.100"), ip("192.168.1.200"))
exclusions = [(ip("192.168.1.150"), ip("192.168.1.159"))]
reservations = {"aa:bb:cc:dd:ee:ff": ip("192.168.1.50")}
pool_size = int(pool[1]) - int(pool[0]) + 1
excluded = sum(int(hi) - int(lo) + 1 for lo, hi in exclusions)
print(f"Pool: {pool_size} addresses, excluded: {excluded}, usable: {pool_size - excluded}")
for mac, addr in reservations.items():
if addr not in network:
print(f"{mac}: {addr} is outside {network}")
elif addr in network and pool[0] <= addr <= pool[1]:
print(f"{mac}: {addr} is inside the pool, make sure it is removed from dynamic use")
else:
print(f"{mac}: {addr} is valid and outside the pool")It prints a usable pool of 91 addresses and reports that the reservation is valid and outside the pool.
Common errors and edge cases
- Overlapping scopes. Two scopes that cover the same addresses on the same segment let two servers offer the same IP. Keep scopes on one subnet from overlapping.
- Two servers, one subnet. For redundancy, a classic approach is the split scope. One server holds about 80% of the pool and the other about 20%, with no overlap. Failover protocols that share lease state are a better option where the software supports them.
- Changing a reservation. A device holding a dynamic lease keeps its old address until it renews or the lease ends. After you add a reservation for a client that already has a lease, release and renew on the client, or wait for the next renewal. A NAK may be needed to push it off the old address.
- MAC randomization. Modern phones and laptops often use a different MAC address for each Wi-Fi network, or rotate it. A reservation keyed to the hardware MAC then never matches. Use the MAC the device shows for that network, or turn off randomization for that network on the device.
- Client identifier mismatch. Some clients send option 61 containing something other than the MAC. A server that matches reservations by MAC will miss them.
- Wrong subnet. A reservation outside the scope's subnet cannot be delivered, because the client could not use the address.
- Pool exhaustion. Clients that cannot get an address end up with 169.254.x.x addresses. A sudden group of link-local clients usually points to a full pool, not a broken network.
Exercise
A /24 subnet uses 192.168.10.0/24. The dynamic pool is 192.168.10.50 to 192.168.10.150. A printer already has the static address 192.168.10.120 configured on the device. (a) How many addresses does the pool contain? (b) What happens if you do nothing about the printer? (c) Give two ways to fix it.
Show answer
(a) 150 - 50 + 1 = 101 addresses. (b) The server can lease 192.168.10.120 to another client, so two hosts use the same IP and both suffer intermittent connectivity problems. Conflict detection may reduce this but does not guarantee prevention. (c) Either exclude 192.168.10.120 from the pool (on a server without an exclusion setting, split the range into 50-119 and 121-150), or give the printer a DHCP reservation. For a reservation, preferably choose an address outside the pool, and set the printer back to automatic configuration.