Can I mechanically add a lease to ISC’s DHCP server? I can think of at least two possible solutions:
- Use the DHCP LDAP patch, and then the LDAP API to add DHCP entries to the LDAP directory.
- Update a file which I can include in
dhcpd.confand restart the server (bah, humbug!) when something changes.
OMAPI is an API for controlling remote applications, and for querying them for
their state. The API can be used to query and maintain leases in ISC’s DHCP
server. The utility du jour for massaging DHCP’s current database of
leases is called
omshell, but due to its interactive nature, it’s a bit messy
to use from a program: I wanted something I could neatly embed in a program. After looking
around for a bit, I found a pure Python implementation for OMAPI called
To enable authenticated OMAPI access to my DHCP server, I
- Created a TSIG key with
dnssec-keygen -a HMAC-MD5 -b 512 -n HOST omky. This key is used to authenticate OMAPI transactions.
- This gives me two files called
K*containing different representations of the symmetric key.
- Add OMAPI support to
- Add a
keystanza with a name and a
secretcontaining the base64-encoded whatsit from one of the key files.
- Add the
- Add a
That suffices to have dhcpd “speak” OMAPI, and I can now go ahead and talk to the server using the API. Here’s a short example in Python. Note that the key name and its secret must match what I’ve configured for the DHCP server.
I can create and delete leases with fixed IP addresses and host names. When I
add a new lease, the
dhcpd.leases file is updated to reflect the
modification. Entries created with OMAPI are permanent – they survive DHCPD
restarts. If an entry is deleted, that is also reflected in the
file and the entry will be cleaned up the next time the file is refreshed by
The line containing the
dynamic option denotes that this host entry did not
dhcpd.conf but was created dynamically via OMAPI.
When I delete the entry, the
dhcpd.leases file shows
This is my small patch to pypureomapi: it adds a static name for the lease which replaces the random name created by dhcpd: