I’ve been using a homebrew sql backend for BIND for a while now. The idea was to make dynamic dns updates easier for my home machines. Its worked pretty well, I like my self written tool, but it lacks a web interface, and it’s also a little clunky. I thought about rewriting it, but i decided to look around and see if something else already existed. A friend mentioned PowerDNS. So I thought I’d give it a shot. I’m loosely following the instructions I found here. These are CentOS 5 directions, but should be similar enough for 6.

Installation

You can install PowerDNS right from yum, if you add in the EPEL repo. I’ll be installing PowerDNS on my DNS server, with a Mysql backend. Mysql is running on a second server. I also have a dedicated web server. So i’ll be installing poweradmin (the web gui) there.

[Undr root@dns ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
Retrieving http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
warning: /var/tmp/rpm-tmp.0NKyoE: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]
[Undr root@dns ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.us.leaseweb.net
 * epel: mirrors.ptd.net
 * extras: yum.singlehop.com
 * updates: yum.singlehop.com
repo id                     repo name                                                           status
base                        CentOS-6 - Base                                                     6,294
epel                        Extra Packages for Enterprise Linux 6 - x86_64                      6,819
extras                      CentOS-6 - Extras                                                       3
updates                     CentOS-6 - Updates                                                    205
repolist: 13,321

I already have MySQL installed, so I’ll skip right to the database creation and then power dns’s setup.

mysql> create database powerdns;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on powerdns.* to 'powerdnsadmin'@'dnsserverip' identified by 'powerdnsadminpass';
Query OK, 0 rows affected (0.04 sec)

mysql> use powerdns;
Database changed
mysql> 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)
    -> );
Query OK, 0 rows affected (0.10 sec)

mysql> CREATE UNIQUE INDEX name_index ON domains(name);
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> CREATE TABLE records (
    -> id INT auto_increment,
    -> domain_id INT DEFAULT NULL,
    -> name VARCHAR(255) DEFAULT NULL,
    -> type VARCHAR(6) DEFAULT NULL,
    -> content VARCHAR(255) DEFAULT NULL,
    -> ttl INT DEFAULT NULL,
    -> prio INT DEFAULT NULL,
    -> change_date INT DEFAULT NULL,
    -> primary key(id)
    -> );
Query OK, 0 rows affected (0.08 sec)

mysql> CREATE INDEX rec_name_index ON records(name);
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> CREATE INDEX nametype_index ON records(name,type);
Query OK, 0 rows affected (0.09 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> CREATE INDEX domain_id ON records(domain_id);
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> CREATE TABLE supermasters (
    -> ip VARCHAR(25) NOT NULL,
    -> nameserver VARCHAR(255) NOT NULL,
    -> account VARCHAR(40) DEFAULT NULL
    -> );
Query OK, 0 rows affected (0.07 sec)

mysql> quit
Bye

Now we actually install power dns.

[Undr root@dns ~]# yum install pdns pdns-backend-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.us.leaseweb.net
 * epel: mirrors.ptd.net
 * extras: yum.singlehop.com
 * updates: yum.singlehop.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pdns.x86_64 0:2.9.22-10.el6 set to be updated
---> Package pdns-backend-mysql.x86_64 0:2.9.22-10.el6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================
 Package                        Arch               Version                     Repository        Size
======================================================================================================
Installing:
 pdns                           x86_64             2.9.22-10.el6               epel             648 k
 pdns-backend-mysql             x86_64             2.9.22-10.el6               epel              29 k

Transaction Summary
======================================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)

Total download size: 677 k
Installed size: 2.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): pdns-2.9.22-10.el6.x86_64.rpm                                           | 648 kB     00:01     
(2/2): pdns-backend-mysql-2.9.22-10.el6.x86_64.rpm                             |  29 kB     00:00     
------------------------------------------------------------------------------------------------------
Total                                                                 381 kB/s | 677 kB     00:01     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
epel/gpgkey                                                                    | 3.2 kB     00:00 ... 
Importing GPG key 0x0608B895 "EPEL (6) " from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing     : pdns-2.9.22-10.el6.x86_64                                                      1/2 
  Installing     : pdns-backend-mysql-2.9.22-10.el6.x86_64                                        2/2 

Installed:
  pdns.x86_64 0:2.9.22-10.el6                pdns-backend-mysql.x86_64 0:2.9.22-10.el6               

Complete!

Now we edit the powerdns config. It’s in /etc/pdns/pdns.conf Find the “launch” section, and add the following (the comments alreayd exist, and are added here for reference):

#################################
# launch        Which backends to launch and order to query them in
#
# launch=

launch=gmysql
gmysql-host=your_db_server
gmysql-user=powerdnsadmin
gmysql-password=powerdnsadminpass
gmysql-dbname=powerdns

Now start up powerdns, and add it to the system startup.

[Undr root@dns ~]# service pdns start
Starting PowerDNS authoritative nameserver: started
[Undr root@dns ~]# chkconfig pdns on

PowerAdmin

Poweradmin is the web interface for PowerDNS. The howto I’m following says to install this on your DNS server. So I’m trying out installing PowerAdmin on my dedicated web server. This server has access to the same database server, so I don’t see why this would be a problem. Download PowerAdmin Here.

[Undr root@armageddon packages]# wget https://www.poweradmin.org/download/poweradmin-2.1.5.tgz
--2012-01-14 15:52:21--  https://www.poweradmin.org/download/poweradmin-2.1.5.tgz
Resolving www.poweradmin.org... 94.142.245.87
Connecting to www.poweradmin.org|94.142.245.87|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 179862 (176K) [application/x-gzip]
Saving to: “poweradmin-2.1.5.tgz”

100%[============================================================>] 179,862      241K/s   in 0.7s    

2012-01-14 15:52:22 (241 KB/s) - “poweradmin-2.1.5.tgz” saved [179862/179862]

Now decompress the archive, and put it in your web tree.

[Undr root@armageddon poweradmin-2.1.5]# cd /var/www/
[Undr root@armageddon www]# mkdir powerdns
[Undr root@armageddon www]# cd powerdns
[Undr root@armageddon powerdns]# tar xvzf ~/packages/poweradmin-2.1.5.tgz 
poweradmin-2.1.5/
poweradmin-2.1.5/delete_perm_templ.php

...

poweradmin-2.1.5/dynamic_update.php
[Undr root@armageddon powerdns]# mv poweradmin-2.1.5 www
[Undr root@armageddon powerdns]# cd www

Now add a virtual host to httpd.


  ServerName poweradmin.your.domain
  ServerAdmin you@yourserver.com
  DocumentRoot /var/www/powerdns/www
  CustomLog logs/powerdns/access_log combined
  ErrorLog logs/powerdns/error_log

Don’t forget to make the log directory, or httpd will fail to restart

[Undr root@armageddon virt.d]# mkdir /var/log/httpd/powerdns

You’ll need epel installed on your web server as well, as listed above. Then there’s a number of php extensions you need. The following should get them all for you.

yum install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt gettext php-pear-DB php-pear-MDB2-Driver-mysql

Now, you should be ready to configure poweradmin. Browse to http://wherever.you.installed.poweradmin/install This walks you through getting your database and other config setup. One thing i had to do was add permission to my db server from my web server for poweradmin. This is done just as it was at the beginning when i first setup the database.

mysql> grant all privileges on powerdns.* to 'powerdnsadmin'@'webserverip' identified by 'powerdnsadminpass';

My next task will be to figure out how to import my bind zonefiles. But, I’ll save that for another blog entry. UPDATE:

Converting from bind

This was going to be a new entry, but it wasnt worth it. It turned out to be so simple. Take your old bind named.conf, and zone files. I put them into a new directory structure which had named.conf in the root, and a sub directory with all of the zonefiles. Then edit the named.conf so that in the “options” stanza, you change the directory to “.”. Then within the directory where you’ve placed all of this data, you run:

[Undr root@dns zones]# zone2sql --named-conf=./named.conf -gmysql > zones.sql 
100% done
12 domains were fully parsed, containing 176 records

This will convert your zones too sql statements, and then put them into the “zones.sql” file. Then you can import that into your powerdns database.