I love being able to have something triggered when a particular event occurs, and in the case of DHCP, I need to launch a program when a DHCP lease is granted. Since version 3.1.0, ISC DHCP can execute a program when a lease changes.

In my dhcpd.conf I have the following rules:

subnet netmask {
    option routers;

    on commit {
        set clip = binary-to-ascii(10, 8, ".", leased-address);
        set clhw = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
        execute("/usr/local/sbin/dhcpevent", "commit", clip, clhw, host-decl-name);

With the on keyword, which takes commit, release or expire, I declare the set of statements I want executed when the event happens.

In the example above, when a lease is granted, the specified program is invoked with the four arguments. What this program does is immaterial, but I believe it should return as quickly as possible. Here's what my dhcpd logs when a lease is granted:

execute_statement argv[0] = /usr/local/sbin/dhcpevent
execute_statement argv[1] = commit
execute_statement argv[2] =
execute_statement argv[3] = 11:aa:bb:cc:dd:ee
execute_statement argv[4] = d1.jp

If you are using the built-in mechanisms for DNS updates, you must not define events, as they are then used internally by dhcpd. (The manual page does, however, give hint at how to overcome that problem.)

You can use this mechanism, say, for updating a DNS server that has no built-in support for RFC 2136 DNS updates, and that is what Tom O'Connor does with DHCP and PowerDNS: his back-end program updates a MySQL database.

Flattr this
DHCP, DNS, and PowerDNS :: 06 Jul 2011 :: e-mail


blog comments powered by Disqus