Install PowerDNS and PowerAdmin on CentOS 7 - How to do it








Are you trying to install PowerDNS on CentOS 7?

This guide is for you.


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.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform CentOS related Packages installation tasks.

In this context, we shall look into how to install PowerDNS.


More information about PowerDNS ?

PowerDNS is an open-source DNS Server program that is written in C++. Also, it is one of the best alternatives for the traditional DNS server.

Generally, it provides two products, the Authoritative server, and the Recursor. We can configure the PowerDNS Authoritative server through different backend that includes the plain Bind zone files, RDBMS such as MySQL, PostgreSQL, SQLite3, or LDAP.

Here, you will learn how to install and configure a PowerDNS Authoritative server with the MariaDB database server as a Backend and using Poweradmin for easy DNS management.


How to install PowerDNS on CentOS 7 ?

Follow the steps given below to install PowerDNS.


1. Installing the EPEL and Remi Repositories

As a first step, we need to install the dependencies. 

i. So we will install the EPEL repository and the REMI for PHP 7.2 installation. 

For that, we run the below commands.

# yum -y install epel-release
# yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

ii. After adding the above repositories, we install the ‘yum-utils’ package.

# yum -y install yum-utils

iii. Then we enable the PHP 7.2 Remi repository using the below command.

# yum-config-manager –enable remi-php72

 

2. Installing and Configuring MariaDB

i. We run the below command to install MariaDB:

# yum -y install mariadb mariadb-server

ii. Once the MariaDB installation completes, we start it and add it to the startup boot time:

# systemctl start mariadb
# systemctl enable mariadb

iii. Now, we configure the root password for the MariaDB using the interactive tool called 'mysql_secure_installation'. 

For that, we run the below command.

# mysql_secure_installation

iv. Now, you will be prompted for configuring the root password. Type 'Y' to set up the root password and enter a strong password.

Set root password? [Y/n] Y

New password:

Re-enter new password:

By now, you have installed the MariaDB server and set up the root password for authentication.

v. Now, we will create a new database and user for the PowerDNS installation. 

For that, log into the MySQL shell with the user root and your password by running the below command:

# mysql -u root -p
PASSWORD

vi. Next, create a new database called 'powerdns' and grant all the database privileges to a new user named 'pdns' with the password 'Password123'.

create database powerdns;
grant all privileges on powerdns.* to pdns@localhost identified by 'Password123';
flush privileges;

vii. Then, create the tables structures for the PowerDNS database by running following MySQL queries below.

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 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);
quit;

Now, a MariaDB database and a user for PowerDNS installation have been created.


3. Install PowerDNS on CentOS 7

i. We run the below command to install the PowerDNS and all its packages by running the below command:

# yum -y install pdns pdns-backend-mysql bind-utils

ii. Once the installation completes, we go to the '/etc/pdns/' directory and edit the configuration file 'pdns.conf' using vim editor:

# cd /etc/pdns/
# vim pdns.conf

PowerDNS uses 'bind' as the backend by default. 

iii. So, type comment '#' in the front of 'launch=bind' configuration and paste the MySQL backend configuration as shown below:

#launch=bind
launch=gmysql
gmysql-host=localhost
gmysql-user=pdns
gmysql-password=pdnspassword2018
gmysql-dbname=powerdns

iv. Now save and close it.

v. Then start the pdns service and add it to the startup boot time:

# systemctl start pdns
# systemctl enable pdns

vi. After that, add the DNS service to the firewall:

# firewall-cmd –add-service=dns –permanent
# firewall-cmd –reload

Now, the PowerDNS service must be up and running well. 

You can check it by running:

# netstat -tap | grep pdns
# netstat -tulpn | grep 53
# dig @10.9.9.10

As a result, you must see the PowerDNS up and running on the port 53.


4. Install PowerAdmin

Now, we need to install a DNS management for PowerDNS called 'Poweradmin'. 

i. Since it is a web application based on PHP, so we need to install PHP and web server in order to run the application.

For that, install an httpd web server and PHP packages using the following command:

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

ii. Once the installation completes, we need to install the PHP Pear packages as well. So run the below command:

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

iii. After the completion of httpd and PHP installation, start the httpd service and add it to the startup boot time:

# systemctl start httpd
# systemctl enable httpd

iv. Then go to the '/var/www/html' directory and download the poweradmin source code:

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

v. Now, extract the poweradmin compressed file and rename it:

# tar xvf poweradmin-2.1.7.tgz
# mv poweradmin-2.1.7/ poweradmin/

vi. After that, add the HTTP and HTTPS protocols to the firewall:

# firewall-cmd –add-service={http,https} –permanent
# firewall-cmd –reload

5. Poweradmin Post-Installation

i. Now, open your web browser and type the server IP address along with the /poweradmin/install/ path URL for the installation.

ii. Select the preferred language and 'Go to Step 2' button.

iii. Now just click the 'Go to Step 3' button.

iv. Now, a database configuration page is displayed. 

Enter the PowerDNS database details that was created earlier and the admin password for PowerDNS.

v. Click the 'Go to Step 4' button.

vi. Then you would need to create a new user with limited privileges. 

vii. Type the necessary details and change the user, password, etc with your own.

viii. Now click the 'Go to Step 5' button.

ix. Re-open your terminal server, log in with the root user and password. 

x. Then run the MySQL queries as on the page:

# mysql -u root -p
PASSWORD
GRANT SELECT, INSERT, UPDATE, DELETE
ON powerdns.*
TO 'hakase'@'localhost'
IDENTIFIED BY 'hakase-labs123';

xi. Now get back to the web browser and click the 'Go to Step 6' button.

xii. If the installer was unable to create a new configuration '../inc/config.inc.php'. Then you need to create it manually.

So for that, go back to the terminal and go to '/var/www/html/poweradmin' directory and create a new configuration file 'inc/config.inc.php':

# cd /var/www/html/poweradmin
# vim inc/config.inc.php

xiii. Then paste the below PHP script on the page:

<?php
$db_host = ‘localhost’;
$db_user = ‘hakase’;
$db_pass = ‘hakase-labs123’;
$db_name = ‘powerdns’;
$db_type = ‘mysql’;
$db_layer = ‘PDO’;
$session_key = ‘xTNxUiXIu320Z@N=uetwJeD2#uApgO)2Ekj+S#oN1Khhoj’;
$iface_lang = ‘en_EN’;
$dns_hostmaster = ‘server.hakase-labs.io’;
$dns_ns1 = ‘ns1.hakase-labs.io’;
$dns_ns2 = ‘ns2.hakase-labs.io’;

xiv. Now save and close the file. This completes the installation.

xv. Now, go back to the web browser and log into the Poweradmin dashboard using the URL as below:

http://10.9.9.10/poweradmin/

Then log in using the default user 'admin' and the password. Then click on the 'Go' button.

As a result, Poweradmin dashboard is shown.


[Need urgent assistance with CentOS queries? – We are here to help you. ]



Conclusion

This article covers the step by step procedure to install PowerDNS on CentOS 7. PowerDNS (pdns) is an open source DNS server written in C++ and released under GPL License. It has become a good alternative for the traditional DNS server Bind, designed with better performance and low memory requirements. 

PowerDNS provides two products, the Authoritative server, and the Recursor. 

The PowerDNS Authoritative server can be configured through the different backend, including the plain Bind zone files, RDBMS such as MySQL, PostgreSQL, SQLite3 or LDAP.


To Install PowerDNS on CentOS 7:

1. First let's start by ensuring your system is up-to-date:

$ yum clean all

$ yum -y update

2. Install PowerDNS and backend.

First, you need to enable EPEL repository and all required packages on your system:

$ yum install epel-release

$ yum install bind-utils pdns pdns-recursor pdns-backend-mysql mariadb mariadb-server

Enable PowerDNS on boot and start PowerDNS server:

$ systemctl enable mariadb

$ systemctl enable pdns

$ systemctl enable pdns-recursor

3. Configure MariaDB.

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

4. Create PowerDNS Database and User in MariaDB.

Login as a MariaDB root and create a new database and tables:

### mysql -uroot -p

5. Configure PowerDNS.

Open the /etc/pdns/pdns.conf file.

Finally, restart the Power DNS service:

$ systemctl restart pdns.service

$systemctl enable pdns.service

6. Configure Recursor.

Open the /etc/pdns-recursor/recursor.conf file.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com