Can DHCP force a client to switch to a static reservation?

I have static IPs for all regular hosts on my network. But rather than configure each distinct host locally I have supplied DHCP the complete set of assignments as static reservations. This works, more or less.

I still have to support dynamic DHCP address assignments for random visitors. So I do have dynamic address support enabled. Which leads to my problem. If a device with a static assignment accidentally gets a dynamic address it seems to be able to hold on to it indefinitely by renewing its lease.

Is there any way to cause DHCP to refuse to renew a device's dynamic lease when it has a static reservation, thereby forcing that device to run through the full lease acquisition process?

The dhcp server will automatically issue the correct IP address to the hosts configured for dhcp reservations. If a given host has an address out of the dynamic pool (prior to when you configure the reservation), the dhcp server will not allow that address to be renewed and will instead offer the newly configured reserved address.

Worth noting: The address won’t change until the host attempts to renew the lease which is done For the first time at 1/2 the lease duration or when the interface goes down/up or the system is restarted. So the timing also depends on the length of the lease, but it will eventually get the updated address.

3 Likes

hate to be a grammar prude... but please call it a "dhcp-fixed" or just a reservation...

if you call this static ... what do you call it when you enter an actual ip address on a device?

A device configured with a static lease will not get a dynamic one.

The DHCP server will always offer to specific hosts the designated address you have configured as a static lease.

I think the key is here:

How can this happen?

I guess this is a hypothetical question, not an actual issue. I have never seen any wrong leases, at least not without user's error.

1 Like

It happens quite often with new devices, if you attach them before configuring a static lease. dnsmasq assigns an address from the dynamic pool and remembers (/etc/leases.dhcp? not in front of my router right now), if you now configure a static lease, the previously assigned/ active dynamic lease retains precedence (until you reboot or stop dnsmasq and remove the dynamic lease from the file).

2 Likes

I just tried it and it didn't happen.
/tmp/dhcp.leases was updated with the new IP address.

Yes. This is the scenario I was trying to describe.

@trendy Are you saying that you tried the scenario @slh described?

Nothing wrong with being a grammar prude. Thanks for pointing out my confusing terminology.

That's right.

On the OpenWrt side, you can only do the following:

  • Use separate ranges for dynamic and static DHCP leases.
  • Minimize the lease time.
  • Manually force wireless clients to reconnect.

Everything else depends on the implementation and configuration of the DHCP client, which in some cases may not even meet the DHCP specification, so you should take that into consideration when comparing the behavior of different devices.

This is correct, it happens all the time with new devices. It's very frustrating because there aren't good web gui or cli tools to handle & view this. The dynamic address keeps getting handed out, even after the fixed address is assigned.
No tool shows a tidy trace or tick box that a client has completed or failed at each step
discover, offer, request, ack, release.
Either the client requests the old address, and odhcp fails to decline it, or odhcp continues giving out the old address, even when it has the new fixed address. Having to restart odhcp manually or force reload is annoying.
On any busy or complex network this is a common issue.

The DHCP server will always offer to specific hosts the designated address you have configured as a static lease - WRONG.
This doesn't happen in practice, until something clears. Perhaps the lease time, or odhcp being in a good mood.
Since there is no way to see what odhcp is up to, there is no definitive answer. It's own internal in memory moody cache seems to override the /tmp/dhcp.leases file or the /etc/config/dhcp file.

Yes there is a good way:

On the LuCI status page, scroll down and find the device you want static and click it.

It is exactly how I made my pi-hole a static address.

1 Like