Ubuntu: BIND and MySQL with SDB

At work, I've been tasked with an assignment to get BIND to function with MySQL so that we can use an already in place PHP Web application to update/maintain DNS entries. Unfortunately, we use SLES at work and I've been battling with this setup ALL WEEK! So, a few hours ago, I wanted to see if the same process was "just as hard" on Ubuntu. Below I will list the steps, and summarize the results. Keep in mind, both the server I use at work and the server I use at home were already up and running with a completely chrooted BIND implementation...and everything working as expected with the BIND files. The only purpose in this exercise was to simply get the backend moved from file updates to a MySQL DB.

Here are the commands I ran:

sudo -s
cd /usr/src
wget http://hivelocity.dl.sourceforge.net/sourceforge/mysql-bind/mysql-bind.tar.gz
tar -xvf mysql-bind.tar.gz
apt-get install dpkg-source dpkg-dev
apt-get install bison libdb-dev libldap2-dev libxml2-dev libcap2-dev hardening-wrapper
#might be more packages here, but you should be prompted on what else is needed
apt-get source bind9
cd bind9-9.5.1.dfsg.P2
cp ../mysql-bind/mysqldb.c bin/named/
cp ../mysql-bind/mysqldb.h bin/named/include/
mysql_config --cflags  #COPY the output for latter use
mysql_config --libs  #COPY the output for latter use
vi bin/named/Makefile.in

...scroll down a bit and you'll see this section, update like so:

  # Add database drivers here.
  DBDRIVER_OBJS = mysqldb.@O@
  DBDRIVER_SRCS = mysqldb.c
  DBDRIVER_INCLUDES = -I/usr/include/mysql -DBIG_JOINS=1 -fPIC \
-fno-strict-aliasing #results of mysql_config --cflags
  DBDRIVER_LIBS = -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql \
-lmysqlclient #results of mysql_config --libs

Next, I edited the main.c file, and simply used vi to search for references of the phrase "xxdb"

vi bin/named/main.c

  * Include header files for database drivers here.
  /* #include "xxdb.h" */
  #include "mysqldb.h"
  * Add calls to register sdb drivers here.
  /* xxdb_init(); */
  * Add calls to unregister sdb drivers here.
  /* xxdb_clear(); */

Then run:

cd /usr/src
dpkg -i *.deb

Next, I opened phpMyAdmin and created a database, table and some default data:


  CREATE TABLE IF NOT EXISTS `thelupine_com` (
  `name` varchar(255) default NULL,
  `ttl` int(11) default NULL,
  `rdtype` varchar(255) default NULL,
  `rdata` varchar(255) default NULL

  INSERT INTO `thelupine_com` (`name`, `ttl`, `rdtype`, `rdata`) VALUES
  ('thelupine.com', 3600, 'SOA', 'thelupine.com. http://www.thelupine.com.
200906201 28800 7200 86400 28800'),
  ('thelupine.com', 3600, 'NS', 'ns.thelupine.com.'),
  ('thelupine.com', 3600, 'MX', '10 mail.thelupine.com.'),
  ('lupunsrv.thelupine.com', 3600, 'A', ''),
  ('mail.thelupine.com', 3600, 'CNAME', 'lupunsrv.thelupine.com.'),
  ('www.thelupine.com', 3600, 'CNAME', 'lupunsrv.thelupine.com.');

Almost ready to restart bind, but first I needed to tell my named.conf.local file to use the MySQL backend now, instead of the bind files:

vi /srv/named/etc/bind/named.conf.local

  zone "thelupine.com" { type master;
  #file "/etc/bind/db.thelupine.com";
  database "mysqldb named thelupine_com MYSQLUSER MYSQLPASSWORD";

...as you can see, I simply commented out (#) the bind file, and gave it the database entry instead.

Finally, stop and restarted bind9

/etc/init.d/bind9 restart

I was able to ping http://www.google.com, as well as http://www.thelupine.com. I then returned back to phpMyAdmin and added some A records to the database, and I was instantly able to ping them. I didn't have to stop and restart bind after adding the records to the database, something I would typically have to do when using the bind files. So I was pleased with the results, as it appeared that not only did everything work as expected, it was EXTERMELY easy and straight forward.....something that has NOT been the same on the SLES box. Even after a week of trying, I STILL can not get the SLES box to work, even though it took less than an hour or so to get it working on Ubuntu 8)