How to Setup PowerDNS and MySQL Backend in Ubuntu Server

Here’s how to setup and configure PowerDNS nameserver with MySQL backend in Ubuntu server. PowerDNS is a high-performance authoritative nameserver with support on various backends such as MySQL, PostgreSQL, Oracle and many other databases. In this tutorial, we will be using MySQL to hold our domain records.
Disclaimer: There is no guarantee that this tutorial will work with your setup nor this site will be held liable to any damage resulting from following this tutorial.
MySQL Installation
Let us install first the MySQL server package through apt-get
sh# apt-get install mysql-server mysql-common
sh# service mysql start
Setting up MySQL
Below are the basic table schema to get you started, you can alter it to your need and purpose.
create database pdns;
create table domains (
id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX name_index ON domains(name);
CREATE TABLE records (
id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(64000) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
primary key(id)
) Engine=InnoDB;
CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
create table supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
) Engine=InnoDB;
Create the required database account which will have access to PowerDNS database
mysql> grant all on pdns.* to puser@localhost identified by ‘password’;
mysql> flush privileges;
PowerDNS Installation
Let us now install PowerDNS through apt-get
sh# apt-get install pdns-server pdns-backend-mysql
PowerDNS Configuration
Edit the PowerDNS configuration file found in /etc/powerdns
#
# MySQL backend configuration details
#
launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=puser
gmysql-password=password
gmysql-dbname=pdns
sh# service pdns monitor
When you start monitor on pdns, you should be able to establish connection to your MySQL server as shown below:
Jul 30 18:52:35 Set effective group id to 117
Jul 30 18:52:35 Set effective user id to 107
Jul 30 18:52:35 Creating backend connection for TCP
% Jul 30 18:52:35 gmysql Connection succesful
Jul 30 18:52:35 About to create 3 backend threads for UDP
Jul 30 18:52:35 gmysql Connection succesful
Jul 30 18:52:35 gmysql Connection succesful
Jul 30 18:52:35 gmysql Connection succesful
Jul 30 18:52:35 Done launching threads, ready to distribute questions
Testing PowerDNS
mysql> INSERT INTO domains (name,type) VALUES(”example-domain.com”,”NATIVE”);
mysql> INSERT INTO records (domain_id,name,content,type,ttl,prio) VALUES(1,”example-domain.com”,”example-domain.com webmaster@example-domain.com”,”SOA”,”86400″,NULL);
mysql> INSERT INTO records (domain_id,name,content,type,ttl,prio) VALUES(1,”example-domain.com”,”1.1.1.1″,”A”,”120″,NULL);
We can then try to lookup the host:
sh# host example-domain.com 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:
example-domain.com has address 1.1.1.1
That’s about it, you have a running PowerDNS nameserver with MySQL database serving as its backend.
Spread the word
del.icio.us Digg Furl Google StumbleUpon Technorati Windows Live Yahoo! Help











Leave a Comment