A Question on Dynamic DHCP/DNS IP Lease Renew

Simon Hobson dhcp1 at thehobsons.co.uk
Thu Sep 29 19:00:06 UTC 2016


David Li <dlipubkey at gmail.com> wrote:

> Thanks again. This is most clearly explained I have seen so far how DDNS works in terms of IP leases.

Thanks, nice to know I can get some things right :-)

> Is the "reserved" statement something I need to add to the /var/lib/dhcp/dhcpd.leases?

Yes

> When I look at that file, it appears to have two identical leases for the same IP address:

They aren't identical :

>  starts 4 2016/09/29 17:38:21;
>  starts 4 2016/09/29 18:03:29;


> Questions:
> 
> 1. Why are there two identical leases?

There aren't.
The explanation is that the leases database is an "append only" format for performance and security reasons. When the server issues a lease, it is required by the RFC to commit that information to persistent storage BEFORE offering it to the client. The fastest form of database is to just append a record to the file.
So the two leases you have found are actually separate ones - one starting at 17:38 and the next starting at 18:03. The last record in the file is the current version, all the previous ones can and will be ignored.

While the server is running, this is a write only file - it is only ever read **ONCE** during server startup when it populates it's internal data structures from the file.

To avoid the file expanding forever, the server re-writes it periodically - by default every hour (compile time option). The new file contains only one record for each lease fetched from the server's internal data structures, is written to a new file, the old file is renamed, and the new file renamed into place - thus making the file replacement almost atomic. The second file (with a timestamp up to an hour earlier than the leases file, is the old version.

> 2. Should I add "reserved;" to both of them?

Only the last - the others aren't used.

> 3. Can this be done without restarting dhcpd?

Only if you use OMAPI.
If you don't use OMAPI you must stop the server before editing the file - otherwise it may append to it while you are editing, or replace it entirely if it does it's cleanup routine. You have to stop and start the server anyway for it to read the file during startup and see any changes you make.



More information about the dhcp-users mailing list