How to Install and Configure ‘PowerDNS’ (with MariaDB) and ‘PowerAdmin’ in RHEL/CentOS 7

PowerDNS is a DNS server running on many Linux/Unix derivatives. It can be configured with different backends including BIND style zone files, relational databases or load balancing/failover algorithms. It can also be setup as a DNS recursor running as a separate process on the server.

The latest version of PowerDNS Authoritative server is 3.4.4, but the one available in the EPEL repository right now is 3.4.3. I would recommend installing the one for the EPEL repository due to the fact that this version is tested in CentOS and Fedora. That way you will also be able to easily update PowerDNS in future.

This article intends to show you how to install and setup master PowerDNS server with a MariaDB backend and the PowerAdmin – a friendly web interface managing tool for PowerDNS.

For the purpose of this article I will be using server with:

Hostname: centos7.localhost 
IP Address 192.168.0.102

Step 1: Installing PowerDNS with MariaDB Backend

1. First you need to enable the EPEL repository for your server simply use:

# yum install epel-release.noarch 
Enable Epel Repository
Enable Epel Repository

2. The next step is to install the MariaDB server. This can be easily done by running the following command:

# yum -y install mariadb-server mariadb
Install MariaDB Server
Install MariaDB Server

3. Next we will configure MySQL to enable and start upon system boot:

# systemctl enable mariadb.service
# systemctl start mariadb.service
Enable Start MariaDB System Boot
Enable Start MariaDB System Boot

4. Now that the MySQL service is running, we will secure and setup a password for MariaDB by running:

# mysql_secure_installation
Follow Instructions
/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  Press ENTER
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y     
New password:  ← Set New Password
Re-enter new password:  ← Repeat Above Password
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y ← Choose “y” to disable that user
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n ← Choose “n” for no
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y ← Choose “y” for yes
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y ← Choose “y” for yes
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

5. Once MariaDB configuration done successfully, we can proceed further with the installation of PowerDNS. This is easily completed by running:

# yum -y install pdns pdns-backend-mysql
Install PowerDNS with MariaDB Backend
Install PowerDNS with MariaDB Backend

6. The configuration file for PowerDNS is located in /etc/pdns/pdns, but before editing it, we will setup a MySQL database for PowerDNS service. First we will connect to the MySQL server and will create a database with name powerdns:

# mysql -u root -p
MariaDB [(none)]> CREATE DATABASE powerdns;
Create PowerDNS Database
Create PowerDNS Database

7. Next, we will create a database user called powerdns:

MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'localhost' IDENTIFIED BY 'tecmint123';
MariaDB [(none)]> GRANT ALL ON powerdns.* TO 'powerdns'@'centos7.localdomain' IDENTIFIED BY 'tecmint123';
MariaDB [(none)]> FLUSH PRIVILEGES;
Create PowerDNS User
Create PowerDNS User

Note: Replace “tecmint123” with the actual password that you want to use for your setup.

8. We proceed by creating the database tables used by PowerDNS. Execute those block by block:

MariaDB [(none)]> USE powerdns;
MariaDB [(none)]> 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)
);
Create Table Domains for PowerDNS
Create Table Domains for PowerDNS
MariaDB [(none)]> CREATE UNIQUE INDEX name_index ON domains(name);
MariaDB [(none)]> 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)
);
Create Index Domains for PowerDNS
Create Index Domains for PowerDNS
MariaDB [(none)]> CREATE INDEX rec_name_index ON records(name);
MariaDB [(none)]> CREATE INDEX nametype_index ON records(name,type);
MariaDB [(none)]> CREATE INDEX domain_id ON records(domain_id);
Create Index Records
Create Index Records
MariaDB [(none)]> CREATE TABLE supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);
Create Table Supermaster
Create Table Supermaster

You can now exit the MySQL console by typing:

MariaDB [(none)]> quit;

9. Finally we can proceed with configuring our PowerDNS in a way that, it will use MySQL as backend. For that purpose open PowerDNS configuration file located at:

# vim /etc/pdns/pdns.conf 

In that file look for the lines looking like this:

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

Just after that put the following code:

launch=gmysql
gmysql-host=localhost
gmysql-user=powerdns
gmysql-password=user-pass
gmysql-dbname=powerdns

Change “user-pass” with the actual password that you set earlier. Here is how my configuration looks like:

Configure PowerDNS
Configure PowerDNS

Save your change and exit from.

10. Now we will start and add PowerDNS to the list of services starting at system boot:

# systemctl enable pdns.service 
# systemctl start pdns.service 
Enable and Start PowerDNS
Enable and Start PowerDNS

At this point your PowerDNS server is up and running. For more information about PowerDNS you can refer to the manual available at http://downloads.powerdns.com/documentation/html/index.html

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Marin Todorov
I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

16 Comments

Leave a Reply
  1. Excellent article. Unlike anything, I was able to find anywhere else. Thanks so much!

    One suggestion I would give to everyone is to determine what PDNS version you have by paying attention to the version number after the yum command. If you are already past that point, run the following command:

    # pdns_control version
    

    Then go to the official website to download the schema that matches the same version that is installed on your system. In my case, I kept using the wrong schema and caused me more frustration than necessary. The schema seems to change between each incremental release and is not forward or backward compatible.

    Reply
  2. I have error when I connect MySQL with pdns with this databases, for fixed I create the format of databases from the official website of 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                    BIGINT 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);
    
    Reply
  3. Hi Ravi,

    I installed powerdns and login in to the poweradmin,but my dns is not resolving.

    [root@server1 ~]# nslookup server2
    ;; Got SERVFAIL reply from 192.168.1.17, trying next server
    ;; Got SERVFAIL reply from 192.168.1.17, trying next server
    ;; Got SERVFAIL reply from 192.168.1.17, trying next server
    Server: 192.168.1.1
    Address: 192.168.1.1#53

    ** server can’t find server2: NXDOMAIN

    Reply
    • @Sanjay,

      Have you tried PowerDNS using default EPEL repository using Yum package manager? if not, try it or compile it from source to get latest version of PowerDNS.

      Reply
  4. I installed powerdns, follow the link https://www.tecmint.com/install-powerdns-poweradmin-mariadb-in-centos-rhel/ .
    When I do dig command into self LAN of the pdns I always receive:

    ;; WARNING: recursion requested but not available

    anything is default setting… where is the log file?

    how can I understand how resolve?

    pdns.conf
    setuid=pdns
    setgid=pdns
    launch=bind

    launch=gmysql
    gmysql-host=localhost
    gmysql-user=powerdns
    gmysql-password=XXXX
    gmysql-dbname=powerdns

    recursor=8.8.8.8

    from my machine to pdns:

    nmap -v -sT 192.168.1.123
    PORT STATE SERVICE
    22/tcp open ssh
    53/tcp open domain
    80/tcp open http
    3306/tcp open mysql

    nmap -v -sU 192.168.1.123
    PORT STATE SERVICE
    53/udp open|filtered domain

    ; <> DiG 9.8.3-P1 <> gs.mydomain.com @192.168.1.123
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 58633
    ;; flags: qr aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: recursion requested but not available

    ;; QUESTION SECTION:
    ;gs.mydomain.com. IN A

    ;; Query time: 1 msec
    ;; SERVER: 192.168.1.123#53(192.168.1.123)
    ;; WHEN: Fri Jul 22 18:15:12 2016
    ;; MSG SIZE rcvd: 31

    no firewall, selinux disabled

    thanks a lot

    Reply
  5. I get “Authentication failed! ” error in GUI , Once i launched the GUI, When i try logging in to the GUI with my admin user and password. Can you help.

    Reply
  6. Actually correct way to create tables would be to use: /usr/share/doc/pdns-backend-mysql-3.X.X folder which consists from database schema files. In case you want to deploy powerdns with DNSSEC, schema will be there.
    mysql -uroot -p powerdns < /usr/share/doc/pdns-backend-mysql-3.X.X/schema.mysql.sql

    Reply
  7. Please update your directions:
    GRANT ALL ON powerdns.* TO ‘powerdns’@’localhost’ IDENTIFIED BY ‘passWord1’;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘‘passWord1’’ at line 1

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.