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 

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

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

# systemctl enable mariadb.service
# systemctl start mariadb.service

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

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;

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

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

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)
);
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)
);
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);
MariaDB [(none)]> CREATE TABLE supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
);

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:

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 

11. Now we will install PowerAdmin – a friendly web interface designed to manager PowerDNS servers. Since it is written in PHP, we will need to install PHP and a web server (Apache):

# yum install 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

PowerAdmin also requires two PEAR packages:

# yum -y install php-pear-DB php-pear-MDB2-Driver-mysql 

You can also refer to the following article for complete instructions how to install LAMP stack in CentOS 7:

  1. Install LAMP in CentOS 7

Once the install is complete, we will need to start and set Apache to start at system boot:

# systemctl enable httpd.service
# systemctl start httpd.service

12. Now that all system requirements for running PowerAdmn are met, we can proceed and download the package. Since the default web directory for Apache is /var/www/html/, we will download the package in there.

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

13. Now, we can now start the web installer of PowerAdmin. Simply open:

http://192.168.0.102/poweradmin-2.1.7/install/

This should bring the first step of the installation:

The above page will ask you to choose the language for your PowerAdmin. Select the one you wish to use and click the “Go to step 2” button.

14. The installer will expect you to have a PowerDNS database:

15. Since we already created one, we can proceed to the next step. You will be asked to enter the database details you setup earlier. You will also need to setup Poweradmin administrator password:

16. Once you have input those, go to step 4. You will create a new user with a limited rights for Poweradmin. The fields that you need to enter here are:

  1. Username – username for the PowerAdmin.
  2. Password – password for the above user.
  3. Hostmaster – When creating SOA records and you have not specified hostmaster, this value will be used.
  4. Primary nameserver – the value will be used as primary name server when creating new DNS zones.
  5. Secondary nameserver – the value will be used as primary name server when creating new DNS zones.

17. On the next step Poweradmin will ask you to create new database user with limited rights on the database tables. It will provide you with the code that you will need to put in a MySQL console:

18. Now open a terminal and run:

# mysql -u root -p

Provide your password and execute the code provided by Poweradmin:

MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE
ON powerdns.*
TO 'powermarin'@'localhost'
IDENTIFIED BY '123qweasd';

19. Now go back to your browser and proceed to the next step. The installer will attempt to create its configuration file in /var/www/html/poweradmin-2.1.7/inc.

The file name is config.inc.php. In case the script is not able to write that file you can create it manually by copying the text and putting it in above mentioned file:

20. Now go to the last page where you will be informed that the installation is complete and will receive information how to access your Poweradmin install:

 

You can enable URLs used by other dynamic DNS providers by running:

# cp install/htaccess.dist .htaccess 

For that purpose you will need to have mod_rewrite enabled in Apache’s configuration.

21. Now it is important to remove the “install” folder from Poweradmin’s root directory with the following command:

# rm -fr /var/www/html/poweradmin/install/

After that you can access your poweradmin at:

http://192.168.0.102/poweradmin-2.1.7/

After logging you should see the Poweradmin main page:

At this point your installation is complete and you are now ready to start managing your DNS zones.

Step 3: How to Add, Edit and Delete DNS Zones in PowerDNS

22. To add new master zone, simply click on the “Add master zone”:

On the next page there are few things that you need to fill:

  1. Domain – domain for which you will be adding the zone.
  2. Owner – sets the owner of the DNS zone.
  3. Template – DNS template – leave to none.
  4. DNSSEC – Donany Name System Security Extensions (optional -check if you need it).

Click the “Add zone” button to add the DNS zone.

Now you can go back to the index page of Poweradmin by clicking the “Index” link. To review all existing DNS zones simply go to “List zones”:

You should now see a list of available DNS zones:

23. To edit an existing DNS zone or add new records click the edit icon:

On the next page you will see the entries for the DNS zone you have chosen:

24. In here to add new DNS zone you will need to set the following information:

  1. Name – name for the entry. Only add the first part of the domain/subdomain, the rest will be added by Poweradmin.
  2. Type – choose the record type.
  3. Priority – priority of the record.
  4. TTL – Time To Live in seconds.

For the purpose of this article, I will add an A record for subdomain new.example.com that will resolve on IP address 192.168.0.102 with time to live 14400 seconds:

Finally click the “Add record” button.

25. If you wish to delete a DNS zone you can go back to the “List zone” page and click on the “Trash” icon next to the DNS zone which you wish to delete:

Poweradmin will ask you if you are sure you want to delete the DNS zone. Simply click “Yes” to finish the deletion.

For more detailed instructions how to create, edit and delete zones you can refer to Poweradmin’s documentation at:

https://github.com/poweradmin/poweradmin/wiki/Documentation

I hope you have find this article interesting and useful. As always if you have any questions or comments please do not hesitate to submit them in the comment section below.