Technology

Installing bind9 on Ubuntu and Integrating with MySQL

A comprehensive guide on setting up bind9 with MySQL integration on Ubuntu 10.10 for DNS server management, including installation steps, database schema, and troubleshooting tips.

Sangrak

Integrating bind9 with MySQL on Ubuntu can be quite unstable. It is not fully developed, so it's recommended to use mydns for MySQL integration instead.

Installation Environment

OS: Ubuntu 10.10, a clean install (VPS) Libraries: apt-get install openssl libssl-dev libmysqlclient-dev dpkg-dev mysql-client

Installation Method

Installing the Program

Navigate to:

cd /usr/local/src

Download the bind9 source:

apt-get source bind9

Configure in the bind9-~ folder:

./configure --prefix=/usr \
	--mandir=\$${prefix}/share/man \
	--infodir=\$${prefix}/share/info \
	--sysconfdir=/etc/bind \
	--localstatedir=/var/run/bind \
	--enable-threads \
	--with-libtool \
	--enable-shared \
	--enable-static \
	--with-openssl=/usr \
	--with-gnu-ld \
	--with-dlz-mysql;
make;
make install;

The executable will be located at /usr/sbin/named, and logs can be found at /var/log/syslog.

Configuration

Edit the configuration file:

vi /etc/bind/named.conf (.local)

Modify as follows:

dlz "Mysql zone" {
	database "mysql
		{host=127.0.0.1 dbname=database_name user=user pass=password}
		{select zone from dns_records where zone = '%zone%'}
		{select ttl, type, mx_priority, case when lower(type)='txt' then concat('"', data, '"') when lower(type) = 'soa' then concat_ws(' ', data, resp_person, serial, refresh, retry, expire, minimum) else data end from dns_records where zone = '%zone%' and host = '%record%'}";
};

Configure the database password accordingly.

If an error occurs due to missing $zone$ token in logs, replace % with $.

Database Schema

Construct the table using:

CREATE TABLE `dns_records` (
	`id` int(11) NOT NULL auto_increment,
	`zone` varchar(64) default NULL,
	`host` varchar(64) default NULL,
	`type` varchar(8) default NULL,
	`data` varchar(64) default NULL,
	`ttl` int(11) NOT NULL default '3600',
	`mx_priority` int(11) default NULL,
	`refresh` int(11) NOT NULL default '3600',
	`retry` int(11) NOT NULL default '3600',
	`expire` int(11) NOT NULL default '86400',
	`minimum` int(11) NOT NULL default '3600',
	`serial` bigint(20) NOT NULL default '2008082700',
	`resp_person` varchar(64) NOT NULL default 'resp.person.email',
	`primary_ns` varchar(64) NOT NULL default 'ns1.yourdns.here',
	`data_count` int(11) NOT NULL default '0',
	PRIMARY KEY  (`id`),
	KEY `host` (`host`),
	KEY `zone` (`zone`),
	KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

named.conf

Edit /etc/bind/named.conf (.options) as follows:

options {
	directory "/etc/bind";
	// Additional configurations removed for brevity
};

Initiating bind9

Create or modify /etc/init.d/bind9 with the necessary startup scripts.

Reference

Manipulating the Database (Query Methods)

Examples provided for managing www.domain.com, domain.com, and alias configurations.

Registering Ubuntu start-up services

To register: update-rc.d -f bind9 defaults To unregister: update-rc.d -f bind9 remove

Error Collection

Error on restart

If encountering errors with rndc, remember it is optional and troubleshooting tips are provided.

Query denied error

Add the following under the options block:

allow-recursion { any; };
allow-query { any; };
allow-query-cache { any; };

For detailed procedures and further guidance, refer to Ubuntu Forums.

More on this topic