PowerDNS is an extremly powerful DNS server. It supports a number of relational database backends, loadbalancing and failover algorithms.
Deploying PowerDNS on all our servers has a few major advantages over our current Bind based setup.
- PowerDNS has native MySQL database backend support and is therefore easier to integrate with our customer control panel. Also changes to the MySQL database are discovered automatically, eliminating the need for periodical restarts. All changes are applied almost instantly.
- PowerDNS can act as a so-called supermaster, synchronizing itsself automatically with slave servers. Zone transfers occur even without adding a domain name to all of the slaves beforehand. It is enough if the domain is added to the database of the master server.
I will now describe how to setup PowerDNS on a Linux box running Debian Woody or Debian Sarge or Debian Lenny and utilizing the MySQL database backend.
Initial Setup
Official Debian packages for PowerDNS are availlable since Debian Sarge, but you can download Woody packages from http://www.powerdns.com/downloads/, if you use Woody. There is no apt repository availlable, however.
After downloading the most recent package with wget, you can install it on your system with dpkg.
wget http://downloads.powerdns.com/releases/deb/stable/pdns-static_2.9.17-1_i386.debdpkg -i pdns-static_2.9.17-1*
If you’ve got a Sarge or newer installation of Debian just run apt-get as follows and the necessary packages will be installed automatically.
apt-get install pdns-recursor pdns-backend-mysql
You’ll notice that PowerDNS will not start up directly after installing the package. That’s because the standard configuration file does not come preconfigured for a specific backend; we have to configure PowerDNS for a backend of our choice first. See below for a sample output of a fresh PowerDNS installation.
/etc/init.d/pdns monitorJun 04 10:13:56 Unable to launch, no backends configured for querying.
Gerneal Settings
Before we will begin to configure the database backend, we’ll have a look at some basic settings first. If you use Sarge, you can skip this part. You will be asked for the information below during configuration of the package. If you use Lenny or Woody, you need to specify an IP address and a port, to which PowerDNS should bind. You should specify an alternate port for non-production use. That allows you to run PowerDNS in parallel to an existing nameserver installation during the initial setup period.
On Woddy and Sarge, edit /etc/powerdns/pdns.conf directly. In Lenny, do edit the file /etc/powerdns/pdns.d/pdns.local file instead. This way it will be easier to update the package later.
vi /etc/powerdns/pdns.d/pdns.locallocal-address=192.168.0.2local-port=5300
If you want to bind PowerDNS to multiple IP addresses change the local-address setting as follows.
local-address=192.168.0.2,192.168.0.3
If your server has multiple IP addresses configured, you should also set the IP address, which PowerDNS will use as the source address when sending out answers to queries from clients or remote servers.
query-local-address=192.168.0.2
MySQL
Before we start to configure PowerDNS to use the MySQL backend, we need to setup the required database and tables.
CREATE DATABASE pdns;USE pdns;CREATE TABLE domains (id INT auto_increment,name VARCHAR(255) NOT NULL,master VARCHAR(20) 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))type=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(6) DEFAULT NULL,content VARCHAR(255) DEFAULT NULL,ttl INT DEFAULT NULL,prio INT DEFAULT NULL,change_date INT DEFAULT NULL,primary key(id))type=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);
We also have to create a new MySQL user account exclusively for PowerDNS and need to set the rights accordingly.
GRANT USAGE ON *.* TO `pdns`@localhost IDENTIFIED BY "********"WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0MAX_UPDATES_PER_HOUR 0;GRANT ALL PRIVILEGES ON `pdns`.`domains` TO `pdns`@localhost;GRANT ALL PRIVILEGES ON `pdns`.`records` TO `pdns`@localhost;GRANT SELECT ON `pdns`.`supermasters`TO `pdns`@localhost;
The neccessary database is now setup and the empty tables await our data. Because PowerDNS is unable to connect using sockets, we have to modify the MySQL configuration and make it bind itsself to localhost.
vi /etc/mysql/my.cnf#skip-networkingbind-address = 127.0.0.1
All we need to do now is to make another change to the PowerDNS configuration.
vi /etc/powerdns/pdns.d/pdns.locallaunch=gmysqlgmysql-host=127.0.0.1gmysql-user=pdnsgmysql-password=********gmysql-dbname=pdns
Let's have a little test of the installation.
/etc/init.d/pdns monitorJun 04 16:46:34 gmysql Connection successful
Perfect. PowerDNS is setup successfully. The initial setup is completed. See you later for part two of this workshop, in which we will insert some random domain data into our new database and setup a typical superserver/slave framework.
Update1: Recently Debian 3.1 Sarge was released. I changed this tutorial a bit to accommodate some differences between Woody and Sarge.
Update2: Actually, PowerDNS is perfectly able to use MySQL sockets, if you omit the gmysql-host option. Lesson learned. Post changed.
Update3: Debian Lenny will be released shortly. I changed this tutorial a bit to accommodate some differences between Woody, Sarge and Lenny.
Tags: debian, dns, howto, pdns, powerdns, workshop
Shameless plug: If this post was useful to you, please consider buying yourself something from one of my Amazon stores: US store, UK store, FR store, DE store, CA store. If you're not into Amazon, why not donate something to GNOME, Mozilla or Wikipedia? Thank you!



And where is this party 2, please?
[...] post is the second part of a workshop on the PowerDNS DNS server. In the first part of this workshop, we set up the PowerDNS server and it’s MySQL database backend. In this part of the workshop, [...]