dhcpd_to_unbound: A Wee Helper Script

Aaron Poffenberger

Like many OpenBSD users, unbound(8) is my internal name resolution daemon, and dhcpd(8) handles IP lease assignments.

Both daemons work well, but don't communiate with one another. I wrote a wee helper script called dhcpd_to_unbound to add assigned addresses from /etc/dhcpd.conf and active leases from /var/db/dhcpd.leases to unbound as local_data. In addition to hostnames, it also adds reverse look-ups.


Usage is very straight forward:

usage: dhcpd_to_unbound [-c file] [-h] [-l file] [-s]
    -c    path to conf to use instead of /etc/dhcpd.conf.
    -h    this message.
    -l    path to leases file to use instead of /var/db/dhcpd.leases.
    -s    show unbound entries for the specified domain.
    -v    verbose.

I have the following in my root crontab(1):

*/3 *   *   *   *   dhcpd_to_unbound
  @reboot             dhcpd_to_unbound

The three-minute interval is just a guess. Pick a value that works for your network.

Notes and Bugs

dhcpd\_to\_unbound only works with the first option domain-name found in /etc/dhcpd.conf, meaning it assumes all clients found in /var/db/dhcpd.leases belong to first the option domain-name found.

It also clears all values for that domain before adding the values it finds.

It probably doesn't work with IPv6, and certainly doesn't validate whether unbound(8) or dhcpd(8) are running.

In other words, it's meant for an IPv4 network in one domain.