PowerDNS + PowerAdmin with Master/Slave replication

I think it is self explaining, what we want to do, Bind is a little bit monolitic and has no api for flexible and dynamic
creation of machines (okay there are some aproaches, but anyhow), Designate was not working well for me … so I started with PowerDNS.
Here are my install notes:

sudo su

Install Epel repository:

yum install epel-release.noarch

Update the system (if not already done)

yum -y update

Install needed Packages, for PowerDNS, for the Httpd Server, some daily tools, MariaDB, since mysql is not anymore in Centos repos.


yum -y install mariadb-server mariadb pdns pdns-backend-mysql vim lynx nmap wget bind-utils php-pear-DB php-pear-MDB2-Driver-mysql httpd php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mhash gettext

Enable services to start while booting and direcly start the services

systemctl enable mariadb.service httpd.service
systemctl start mariadb.service httpd.service

# Start with setting a root password / finalize mariadb


mysql_secure_installation

except of:
Disallow root login remotely? [Y/n]
where you choose N (no) instead of default yes, you can take the default values and set a root password.

Now we start with the creation of the database:
1.st login via root to the database


mysql -u root -p

You should now be logged in to mysql, so we can create a database called pdns:


CREATE DATABASE pdns;

Now we create a user „powerdns“ and grant them rights to the database „pdns“ from localhost, as well as from official hostname:


GRANT ALL ON pdns.* TO 'powerdns'@'localhost' IDENTIFIED BY ‘secure’;
GRANT ALL ON pdns.* TO 'powerdns'@'ns1.mydomain' IDENTIFIED BY 'secure';
FLUSH PRIVILEGES;

Execute the following sql to create the tables with needed fields (For this version)


USE 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,
  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);


exit

Now you should be back on normal Shell, so we can continue with the Config file:

vim /etc/pdns/pdns.conf

„allow-axfr-ips“ has to be changed to slave PowerDNS Server, as well as „also-notify“ IP
the default-soa-name is the fqdn of your primary nameserver.


allow-axfr-ips=192.168.27.31
default-soa-name=ns1.mydomain.com.

launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=secure
gmysql-dbname=pdns
soa-minimum-ttl=3600
soa-refresh-default=10800
soa-retry-default=3600

master=yes
also-notify=192.168.27.31

experimental-json-interface=yes
experimental-api-key=secure-it
webserver=yes
webserver-address=192.168.28.79
webserver-port=8081


lets start the service:


service pdns start

since it is now up and running, lets download and configure the nice PowerDNS webinterface
PowerAdmin

cd /var/www/html/
wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
tar xfv poweradmin-2.1.7.tgz

Open a Browser and start the installer/configuration:


http://192.168.28.79/poweradmin-2.1.7/install/

Copy the snippet at the end (there is a missing ?> at the end… so put it there later)
then go back to the Terminal

cd poweradmin-2.1.7
vim inc/config.inc.php

Insert your data like the following:





Remove and move stuff around …


mv install/ initial_install
mv * ../
cd ../
rm -rf poweradmin-2.1.7*

Thats it for the master / primary Nameserver, now we continue on the secondary / slave Nameserver.
So we just change a litle bit from the configuration of the master. To be more concrete, here is the pdns config of the slave:


vim /etc/pdns/pdns.conf

default-soa-name=ns1.mydomain.com.
launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=secure
gmysql-dbname=pdns
soa-minimum-ttl=3600
soa-refresh-default=10800
soa-retry-default=3600

slave=yes
allow-notify-from=192.168.28.0/24,192.168.27.0/24

After you finished all the steps on the slave Server, you can go to the Webinterface of the slave and klick on „Add supermaster“,
where you put the IP of your primary PowerDNS Server.

Thats it… Really !! Now you can use the api to add subdomains or hosts …

Here are some Examples (you need curl and jq installed), if you want to use PTR Records (recommended) „set-ptr“: true, you need an in-addr.arpa for each subnet:

API Examples for PowerDNS
List zones

curl -H 'X-API-Key: secure-it' http://192.168.28.79:8081/servers/localhost/zones | jq .

Create new zone „test.mydomain.com“ with nameservers ns1.mydomain.com, ns2.mydomain.com

curl -X POST --data '{"name":"test.mydomain.com", "kind": "master", "masters": [], "nameservers": ["ns1.mydomain.com", "ns2.mydomain.com"]}' -v -H 'X-API-Key: secure-it' http://192.168.28.79:8081/servers/localhost/zones | jq .

Show the new zone

curl -H 'X-API-Key: secure-it' http://192.168.28.79:8081/servers/localhost/zones/test.mydomain.com | jq .

Add a new record to the new zone (would replace any existing machine-01.test.mydomain.com/A records)

curl -X PATCH --data '{"rrsets": [ {"name": "machine-01.test.mydomain.com", "type": "A", "changetype": "REPLACE", "records": [ {"content": "192.168.28.76", "disabled": false, "set-ptr": true , "name": "machine-01.test.mydomain.com", "ttl": 86400, "type": "A" } ] } ] }' -H 'X-API-Key: secure-it' http://192.168.28.79:8081/servers/localhost/zones/test.mydomain.com | jq .

Combined replacement of multiple RRsets

curl -X PATCH --data '{"rrsets": [
  {"name": "machine-01.test.mydomain.com",
   "type": "A",
   "changetype": "REPLACE",
   "records": [ {"content": "192.168.28.76", "disabled": false, "set-ptr": true , "name": "machine-01.test.mydomain.com", "ttl": 86400, "type": "A" } ]
  },
  {"name": "testlab-01.test.mydomain.com",
   "type": "A",
   "changetype": "REPLACE",
   "records": [ {"content": "192.168.28.20", "disabled": false, "set-ptr": true , "name": "testlab-01.test.mydomain.com", "ttl": 86400, "type": "A" } ]
  }
  ] }' -H 'X-API-Key: secure-it' http://192.168.28.79:8081/servers/localhost/zones/test.mydomain.com | jq .


Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.