Since our SVN server isn't really know for its stability; Sorry for the bad formatting


Compile and run Bind9 (9.4.2) on Hardy Heron Server 8.04.1

For some time I have been looking for howto's on this topic however have come up empty; A Post (I also borrowed some of drmoocows examples in this text) on the ubuntu forums lead me to getting started on my attempts again. So after a few hours here is the howto for a working DNS server.

Get the sources

apt-get install dpkg-dev
mkdir -p /usr/local/src/bind9
cd /usr/local/src/bind9
apt-get source bind9
mkdir -p /usr/local/src/mysql
cd /usr/local/src/mysql
apt-get source mysql-server


Get the build essentials

apt-get update
apt-get install mysql-common libncurses5-dev libwrap0-dev libreadline5-dev chrpath automake1.9 doxygen texlive-latex-base gs dpatch gawk fakeroot bison libtool libssl-dev build-essential debhelper gcc

You may also want to install something to administer the MySQL server which is my preferred method which you can do by adding phpmyadmin to the apt-get install list.
Build MySQL & Install

dpkg-buildpackage -rfakeroot -b
cd ..
dpkg -i *.deb


Build Bind9 & Install

cd /usr/local/src/bind9/bind9-9.4.2/
vim debian/rules

Look for the section starting with "configure-stamp:". You'll be adding a flag to the commandline - I added a backslash to the last option, and added --with-dlz-mysql on the next line, also consider --disable-threads \ as they dont work any on a Linux system according to the doco at http://bind-dlz.sourceforge.net/mysql_driver.html

dpkg-buildpackage -rfakeroot -b
cd ..
dpkg -i *.deb

Now you should have both MySQL and Bind compiled and installed and even running with any luck its time to configure Bind


Configuration /etc/bind/named.conf.local

dlz "Mysql zone" {
database "mysql
{host=127.0.0.1 dbname=changeme port=3306 user=changeme pass=changeme}
{select zone from dns_records where zone = '%zone%'}
{select ttl, type, mx_priority, case when lower(type)='txt' then concat('\"', data, '\"')
else data end from dns_records where zone = '%zone%' and host = '%record%'
and not (type = 'SOA' or type = 'NS')}
{select ttl, type, mx_priority, data, resp_person, serial, refresh, retry, expire, minimum
from dns_records where zone = '%zone%' and (type = 'SOA' or type='NS')}
{select ttl, type, host, mx_priority, data, resp_person, serial, refresh, retry, expire,
minimum from dns_records where zone = '%zone%' and not (type = 'SOA' or type = 'NS')}
{select zone from xfr_table where zone = '%zone%' and client = '%client%'}
{update data_count set count = count + 1 where zone ='%zone%'}";
};

You may also want to add forwarders in BIND if you plan to use the server for Internet address lookups.


SQL Here is some test DNS data for you to use

-- phpMyAdmin SQL Dump
-- version 2.11.3deb1ubuntu1.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 24, 2008 at 07:19 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.4-2ubuntu5.3

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `bind`
--
CREATE DATABASE `bind` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `bind`;

-- --------------------------------------------------------

--
-- Table structure for table `dns_records`
--

CREATE TABLE IF NOT EXISTS `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 AUTO_INCREMENT=9 ;

--
-- Dumping data for table `dns_records`
--

INSERT INTO `dns_records` (`id`, `zone`, `host`, `type`, `data`, `ttl`, `mx_priority`, `refresh`, `retry`, `expire`, `minimum`, `serial`, `resp_person`, `primary_ns`, `data_count`) VALUES
(7, 'domain.com', 'www2', 'CNAME', 'www.domain.com.', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(6, 'domain.com', '@', 'A', '1.2.3.4', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(5, 'domain.com', 'www', 'A', '1.2.3.4', 3600, NULL, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0),
(8, 'domain.com', '@', 'MX', 'domain.com.', 3600, 0, 3600, 3600, 86400, 3600, 2008082700, 'resp.person.email', 'ns1.yourdns.here', 0);


Testing You should now be able to use your DNS server if you dont get something like below go back over the steps and feel free to contact Kahn in IRC at irc://dm1.irc.the-mesh.org:6667 #themesh

root@ns1:/usr/local/src/bind9# dig www.domain.com @127.0.0.1

; <<>> DiG 9.4.2-P1 <<>> www.domain.com @127.0.0.1
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3212
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.domain.com. IN A

;; ANSWER SECTION:
www.domain.com. 3600 IN A 1.2.3.4

;; Query time: 13 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Sep 24 19:52:11 2008
;; MSG SIZE rcvd: 48

root@ns1:/usr/local/src/bind9#