PowerDNS is a DNS server, written in C++ and licensed under the GPL. It runs on most Unix derivatives. PowerDNS features a large number of different backends ranging from simple BIND style zonefiles to relational databases and load balancing/failover algorithms. A DNS recursor is provided as a separate program.
Installation of the PowerDNS Authoritative server on UNIX systems can be done in several ways:
Install updates:
# apt-get install --fix-broken && apt-get update -y && sudo apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y
Installing MySQL
In order to install MySQL, we run
# apt-get install mysql-server mysql-client
We want MySQL to listen on all interfaces (this is important for MySQL database replication!), not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1:
vi /etc/mysql/my.cnf
Then we restart MySQL:
# service mysql restart
Now check that networking is enabled. Run
# netstat -tap | grep mysql
The output should look like this:
root@NS01~# netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 952/mysqld
Installing PowerDNS
To install PowerDNS, we run
# apt-get install -y pdns-server pdns-backend-mysql
You will be prompted to configure the MySQL backend. We will perform this process manually in a moment, so use the arrow keys to select
Now we connect to MySQL:
# mysql -u root -p
Type in your MySQL root password, and you should be on the MySQL shell. On the MySQL shell, we create a database for PowerDNS:
CREATE DATABASE powerdns;
grant all privileges on powerdns.* to power_user@localhost identified by 'TypeYourPasswordHere';
FLUSH PRIVILEGES;
Now we create the tables needed by PowerDNS...
use powerdns;
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,
disabled TINYINT(1) DEFAULT 0,
ordername VARCHAR(255) BINARY DEFAULT NULL,
auth TINYINT(1) DEFAULT 1,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
CREATE INDEX recordorder ON records (domain_id, ordername);
CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
CREATE TABLE comments (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
type VARCHAR(10) NOT NULL,
modified_at INT NOT NULL,
account VARCHAR(40) NOT NULL,
comment VARCHAR(64000) NOT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX comments_domain_id_idx ON comments (domain_id);
CREATE INDEX comments_name_type_idx ON comments (name, type);
CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
CREATE TABLE domainmetadata (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
kind VARCHAR(32),
content TEXT,
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
CREATE TABLE cryptokeys (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
PRIMARY KEY(id)
) Engine=InnoDB;
CREATE INDEX domainidindex ON cryptokeys(domain_id);
CREATE TABLE tsigkeys (
id INT AUTO_INCREMENT,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
PRIMARY KEY (id)
) Engine=InnoDB;
CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
When using the InnoDB storage engine, we suggest adding the following lines to the 'create table records' command above:
CONSTRAINT `records_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domains`
(`id`) ON DELETE CASCADE
Or, if you have already created the tables, execute:
ALTER TABLE `records` ADD CONSTRAINT `records_ibfk_1` FOREIGN KEY (`domain_id`)
REFERENCES `domains` (`id`) ON DELETE CASCADE;
Configure PowerDNS
We have to configure PowerDNS to use our new database.
First, remove the existing configuration files:
# rm /etc/powerdns/pdns.d/*
Now we can create the MYSQL configuration file:
# vi /etc/powerdns/pdns.d/pdns.local.gmysql.conf
Enter the following data into the file. Remember to add your own database settings for gmysql-dbname, gmysql-user, and especially gmysql-password.
# MySQL Configuration file
launch=gmysql
gmysql-host=localhost
gmysql-dbname=powerdns
gmysql-user=powerdns_user
gmysql-password=powerdns_user_password
Restart PowerDNS to apply changes:
# service pdns restart
Check if PowerDNS is listening:
#netstat -tap | grep pdns
Check if PowerDNS responds correctly:
#dig @127.0.0.1
You should see an output similar to:
root@NS01:~# dig @127.0.0.1
; <<>> DiG 9.9.5-9+deb8u13-Debian <<>> @127.0.0.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18854
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1680
;; QUESTION SECTION:
;. IN NS
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Sat 09 09:10:04 SAST 2017
;; MSG SIZE rcvd: 28
NB: You won't encounter the following error if you follow this guide:
pdns[23281]: Backend reported permanent error which prevented lookup (GSQLBa.
The installation is not finished...I do not issue any guarantee that this will work for you! but worked for me.
PowerDNS comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. This is free software, and you are welcome to redistribute.
Reference:
https://doc.powerdns.com/md/authoritative/installation/