How to Install PowerDNS on CentOS 8 (Part 1)

03 October 2020 | Category : CentOS

How to Install PowerDNS on CentOS 8 (Part 1)

What is PowerDNS?

PowerDNS is an open-source authoritative DNS Server, written in C++ and licensed under GPL/GNU and also an alternative of BIND DNS. PowerDNS (PDNS) have a better performance which is can be installed with many support backends like with SQL platforms such as MySQL, MariaDB, and PostgreSQL. However, PowerDNS also still can configure with backend Bind style zone files.

In this article, we will share about How to Install PowerDNS on CentOS 8. Maybe many people out there or the new guys in System administration still don’t understand how to install and configuration PowerDNS with PowerAdmin on CentOS. So in this article, we share about step by step to install PowerDNS with PowerAdmin.

Install PowerDNS on CentOS 8

To install PowerDNS on CentOS 8 we will inform you first, in this article we will install PowerDNS with MySQL/MariaDB backend. So, to install the PowerDNS with MySQL/MariaDB backend we need to install the MySQL/MariaDB Server and the first step is Install MySQL/MariaDB server.

  1. Install MariaDB/MySQL Server

As we said before we need to install the MySQL/MariaDB first. To install MySQL/MariaDB you can run this command :

yum install -y mariadb-server mariadb

After the installation progress finished you can enable and start the service MySQL/MariaDB service with this command :

systemctl start mariadb
systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

Then you can run command the mysql secure installation with this command :

mysql_secure_installation

Maybe you can read more about this step on our last article at How to Install MariaDB on CentOS 8

The next step is to create a database for PowerDNS, to create the database you can login the database with user root with this command :

mysql -u root -p

And then you can run the below command to create a database, create a user, and switch into the database which will use.

create database powerdns;
grant all privileges on powerdns.* to 'powerdns'@'localhost' identified by 'LKFtZH79uEXAcD';
use powerdns;

After the database switch into database powerdns, you can create several tables like domains, records, supermasters with the below command :

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 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(6) DEFAULT NULL,
  content VARCHAR(255) DEFAULT NULL,
  ttl INT DEFAULT NULL,
  prio INT DEFAULT NULL,
  disabled TINYINT(1) DEFAULT 0,
  change_date INT DEFAULT NULL,
  primary key(id)
);

CREATE INDEX rec_name_index ON records(name);

CREATE INDEX nametype_index ON records(name,type);

CREATE INDEX domain_id ON records(domain_id);

CREATE TABLE supermasters (
  ip VARCHAR(25) NOT NULL,
  nameserver VARCHAR(255) NOT NULL,
  account VARCHAR(40) DEFAULT NULL
);

If you are done with this step now you can continue to the next step to install the PowerDNS server.

  1. Install PowerDNS

In this step, before you install PowerDNS you need to add the repository EPEL dan REMI first. To do that you can run the below command :

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-8.rpm

After that you can run the command installation with this command :

yum install -y pdns-backend-mysql pdns

If the PowerDNS package has been installed successfully you need edit the configuration file of PowerDNS with this command :

vim /etc/pdns/pdns.conf

In the file pdns.conf you will find the line configuration which not comment at this line :

launch=bind

You can comment that line or change that line configuration to this configuration below :

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

The above configuration it’s mean we use MySQL/MariaDB as a backend of PowerDNS.

And then you can restart the service PowerDNS and also enable the service of PowerDNS with this command :

systemctl restart pdns
systemctl enable pdns
Created symlink /etc/systemd/system/multi-user.target.wants/pdns.service → /usr/lib/systemd/system/pdns.service.

To manage the PowerDNS you need the interface. in this article, we will use the PowerAdmin as a simple Web Interface to manage the PowerDNS with a web browser. Before you manage the PowerDNS you can follow the next step to install PowerAdmin with Nginx Web Server.

  1. Install PowerAdmin with Nginx

To use PowerAdmin as the web-based interface of management PowerDNS you need to Install Nginx and PHP first. To install Nginx and PHP on you CentOS you can follow this command :

yum install -y nginx php-fpm php-cli php-mysqlnd php72-php-pecl-mcrypt php-json

After the package of Nginx and PHP has been installed you can edit the PHP-FPM configuration with the below command :

vim /etc/php-fpm.d/www.conf

On this file configuration www.conf you can make sure if the socket of PHP-FPM is running on path /run/php-fpm/www.sock like below configuration :

listen = /run/php-fpm/www.sock

If the socket PHP-FPM is correct you can continue to the next configuration to change the owner permission on folder /var/lib/php/session to use apache as ownership with this command :

chown apache:apache /var/lib/php/session

And then the next configuration is to create a virtual host (server block) for the PowerAdmin. In here article, an example we installed PowerAdmin uses a subdomain nacht.manageserver.my.id for access PowerAdmin to manage the PowerDNS. So, you can follow this command to create a virtual host :

vim /etc/nginx/conf.d/nacht.manageserver.my.id.conf

Note :
For file nacht.manageserver.my.id.conf you can change the name with your subdomain or domain name for the PowerAdmin access.

In this file virtual host you can field the configuration with below configuration :

server {
      server_name nacht.manageserver.my.id;
      listen 80;

      root /var/www/html/nacht.manageserver.my.id;
      access_log /var/log/nginx/nacht.manageserver.my.id_access.log;
      error_log /var/log/nginx/nacht.manageserver.my.id_error.log;

      index index.php;

      location / {
      try_files $uri $uri/ /index.php?query_string;
      }

      location ~ \.php$ {
         fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(.*)$;
      fastcgi_keep_conn on;
      include /etc/nginx/fastcgi_params;
      fastcgi_pass unix:/run/php-fpm/www.sock;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }

      location ~/\.ht {
      deny all;
      }

   }

Note :
For line configuration which uses nacht.manageserver.my.id you can change with your subdomain or domain.

To check the virtual host configuration you can try running this command :

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If the result show like the output in above you can restart the nginx service with this command :

systemctl restart nginx

Now, you can create a folder root document of PowerAdmin an example on folder /var/www/html/nacht.manageserver.my.id and change the ownership that folder to apache with the below command :

mkdir -p /var/www/html/nacht.manageserver.my.id
chown -R apache:apache /var/www/html/nacht.manageserver.my.id

Note :
You can change name of folder nacht.manageserver.my.id with the folder name you want or with the name of your subdomain

If the folder root document has been created you can download or clone the PowerAdmin with this command :

cd /var/www/html/nacht.manageserver.my.id
git clone https://github.com/poweradmin/poweradmin.git
mv poweradmin/* .
rm -rf poweradmin/

To install the PowerAdmin you can access your subdomain with url http://your_subdomain/install an example like this http://nacht.manageserver.my.id//install/


In the first step you will see the above configuration, this step to choose the language for PowerAdmin. So, you can choose I prefer to proceed in english and then you can click Go to step 2


Next step, you will see agreement installation. So you can click Go to step 3 if you sure to install the PowerAdmin.


In step 3 you will fill up the database configuration. You can fill that with your database created before at the last step Install MariaDB/MySQL Server and click Go to step 4


At step 4 you will be asked to fill up your Private Nameserver configuration also username and password for login to PowerAdmin. on Primary and Secondary nameserver right there example we create chrono.manageserver.my.id and yami.manageserver.my.id for Private Nameserver, after you finish type your Private Nameserver click Go to step 5


In step 5 you will be asked to limited access to the database, but this step you have been set before at step Install MariaDB/MySQL Server. You can skip this step and click Go to step 6


At step 6, you will be asked to create a file configuration on /var/www/html/nacht.manageserver.id/inc/config.inc.php with the above configuration. You can copy that configuration and then you can run this command to edit/create the file configuration :

vim /var/www/html/nacht.manageserver.id/inc/config.inc.php

Now, paste the configuration above to the file and edit on line db_pass fill up with your password of user database powerdns. If you finished with this you can click Go to step 7


On the last step, you will be asked to delete the folder install, After you deleted that folder you can try to access your PowerAdmin with url http://yoursubdomain.com and it will be shown like this.

Conclusion

PowerDNS is one of the famous DNS Server applications and this is an alternative of BIND (named) DNS Server. To control or manage the PowerDNS you can use PowerAdmin as a web-based interface, when used PowerAdmin you can create your Private Nameserver and manage your DNS configuration.

Share this article :