{"id":2961,"date":"2019-06-05T09:02:53","date_gmt":"2019-06-05T06:02:53","guid":{"rendered":"https:\/\/kifarunix.com\/?p=2961"},"modified":"2021-11-27T19:24:15","modified_gmt":"2021-11-27T16:24:15","slug":"install-powerdns-with-mariadb-backend-on-fedora-30-29-centos-7","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-powerdns-with-mariadb-backend-on-fedora-30-29-centos-7\/","title":{"rendered":"Install PowerDNS with MariaDB Backend on Fedora 30\/29\/CentOS 7"},"content":{"rendered":"\n<p>In this guide, we are going to learn how to install <a rel=\"noreferrer noopener\" aria-label=\"PowerDNS (opens in a new tab)\" href=\"https:\/\/doc.powerdns.com\/\" target=\"_blank\">PowerDNS<\/a> with MariaDB backend on Fedora 30\/29\/CentOS 7. PowerDNS is a powerful opensource DNS server that provides alternative DNS services to BIND.  It provides two nameserver products namely, the Authoritative Server and the Recursor. <\/p>\n\n\n\n<p>While the Authoritative Server only answer questions about domains it knows about, Recursor on the other hand has no knowledge of domains itself  by default it will always consult other authoritative servers to answer questions given to it.<\/p>\n\n\n\n<p>The authoritative PowerDNS server supports different backends ranging from database backends such as MySQL,&nbsp;PostgreSQL,&nbsp;Oracle and&nbsp;<a href=\"https:\/\/doc.powerdns.com\/authoritative\/backends\/bind.html\" target=\"_blank\" rel=\"noopener\">BIND zone files<\/a>&nbsp;to&nbsp;<a href=\"https:\/\/doc.powerdns.com\/authoritative\/backends\/pipe.html\" target=\"_blank\" rel=\"noopener\">co-processes<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/doc.powerdns.com\/authoritative\/backends\/remote.html\" target=\"_blank\" rel=\"noopener\">JSON API\u2019s<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install PowerDNS with MariaDB Backend on Fedora 30\/29\/CentOS 7<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Install PowerDNS on Fedora 30\/29\/CentOS 7<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Update and upgrade your system.<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>yum update\nyum upgrade<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install MariaDB<\/h4>\n\n\n\n<p>In this guide, we will use MariaDB as the PowerDNS backend. Hence before you can proceed, you need to install and configure MariaDB.<\/p>\n\n\n\n<p>See our guide on how to install MariaDB 10.3 by following the links below;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-mariadb-10-3-on-fedora-30\/\" target=\"_blank\">Install MariaDB 10.3 on Fedora 30<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-mariadb-10-3-on-centos-7\/\" target=\"_blank\">Install MariaDB 10.3 on CentOS 7<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring MariaDB Backend for PowerDNS<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Create PowerDNS MariaDB User and Database<\/h4>\n\n\n\n<p>Once the installation is done, proceed to create MariaDB database and user for PowerDNS.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>create database powerdns;\ngrant all privileges on powerdns.* to dnsadmin@localhost identified by 'StrongP@SS';<\/code><\/pre>\n\n\n\n<p>Next,  use the PowerDNS database created above and run the following commands to create the table structures.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>use powerdns;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE domains (\n  id                    INT AUTO_INCREMENT,\n  name                  VARCHAR(255) NOT NULL,\n  master                VARCHAR(128) DEFAULT NULL,\n  last_check            INT DEFAULT NULL,\n  type                  VARCHAR(6) NOT NULL,\n  notified_serial       INT UNSIGNED DEFAULT NULL,\n  account               VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL,\n  PRIMARY KEY (id)\n) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE UNIQUE INDEX name_index ON domains(name);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE records (\n  id                    BIGINT AUTO_INCREMENT,\n  domain_id             INT DEFAULT NULL,\n  name                  VARCHAR(255) DEFAULT NULL,\n  type                  VARCHAR(10) DEFAULT NULL,\n  content               VARCHAR(64000) DEFAULT NULL,\n  ttl                   INT DEFAULT NULL,\n  prio                  INT DEFAULT NULL,\n  disabled              TINYINT(1) DEFAULT 0,\n  ordername             VARCHAR(255) BINARY DEFAULT NULL,\n  auth                  TINYINT(1) DEFAULT 1,\n  PRIMARY KEY (id)\n) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX nametype_index ON records(name,type);\nCREATE INDEX domain_id ON records(domain_id);\nCREATE INDEX ordername ON records (ordername);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE supermasters (\n  ip                    VARCHAR(64) NOT NULL,\n  nameserver            VARCHAR(255) NOT NULL,\n  account               VARCHAR(40) CHARACTER SET 'utf8' NOT NULL,\n  PRIMARY KEY (ip, nameserver)\n) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE comments (\n     id                    INT AUTO_INCREMENT,\n     domain_id             INT NOT NULL,\n     name                  VARCHAR(255) NOT NULL,\n     type                  VARCHAR(10) NOT NULL,\n     modified_at           INT NOT NULL,\n     account               VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL,\n     comment               TEXT CHARACTER SET 'utf8' NOT NULL,\n     PRIMARY KEY (id)\n     ) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX comments_name_type_idx ON comments (name, type);\nCREATE INDEX comments_order_idx ON comments (domain_id, modified_at);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE domainmetadata (\n    id                    INT AUTO_INCREMENT,\n    domain_id             INT NOT NULL,\n    kind                  VARCHAR(32),\n    content               TEXT,\n    PRIMARY KEY (id)\n    ) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE cryptokeys (\n  id                    INT AUTO_INCREMENT,\n  domain_id             INT NOT NULL,\n  flags                 INT NOT NULL,\n  active                BOOL,\n  content               TEXT,\n  PRIMARY KEY(id)\n) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE INDEX domainidindex ON cryptokeys(domain_id);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE tsigkeys (\n  id                    INT AUTO_INCREMENT,\n  name                  VARCHAR(255),\n  algorithm             VARCHAR(50),\n  secret                VARCHAR(255),\n  PRIMARY KEY (id)\n) Engine=InnoDB;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);<\/code><\/pre>\n\n\n\n<p>Next, you need to add foreign key constraints to the tables in order to automate deletion of records, key material, and other information upon deletion of a domain from the domains table. This ensures that no records, comments or keys exists for domains that you already removed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE records ADD CONSTRAINT `records_domain_id_ibfk` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;\nALTER TABLE comments ADD CONSTRAINT `comments_domain_id_ibfk` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;\nALTER TABLE domainmetadata ADD CONSTRAINT `domainmetadata_domain_id_ibfk` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;\nALTER TABLE cryptokeys ADD CONSTRAINT `cryptokeys_domain_id_ibfk` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install PowerDNS<\/h3>\n\n\n\n<p>Once the configuration of database is done, proceed to install PowerDNS.<\/p>\n\n\n\n<p>On Fedora 30, PowerDNS is available on the default repos and thus can be simply installed by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dnf install pdns pdns-backend-mysql bind-utils<\/code><\/pre>\n\n\n\n<p>For CentOS 7, you need to install EPEL repos.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install epel-release\nyum install pdns pdns-backend-mysql bind-utils<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure PowerDNS Backend<\/h3>\n\n\n\n<p>PowerDNS uses bind as the default backend. Therefore, open the PowerDNS configuration and comment out the line, <strong>launch=bind<\/strong>, replace it with the following lines. Replace you configs accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/pdns\/pdns.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n#launch=bind\nlaunch=gmysql\ngmysql-host=127.0.0.1\ngmysql-user=dnsadmin\ngmysql-dbname=powerdns\ngmysql-password=StrongP@SS\n...<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Verify PowerDNS connection to Backend<\/h4>\n\n\n\n<p>Before you can start PowerDNS, run in it in foreground as shown below to verify the connection to MariaDB backend.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>pdns_server --daemon=no --guardian=no --loglevel=9<\/code><\/pre>\n\n\n\n<p>If all is well, then;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\nJun 05 01:24:36 Creating backend connection for TCP\nJun 05 01:24:36 gmysql Connection successful. Connected to database 'powerdns' on '127.0.0.1'.\nJun 05 01:24:36 About to create 3 backend threads for UDP\nJun 05 01:24:36 gmysql Connection successful. Connected to database 'powerdns' on '127.0.0.1'.\nJun 05 01:24:36 gmysql Connection successful. Connected to database 'powerdns' on '127.0.0.1'.\nJun 05 01:24:36 gmysql Connection successful. Connected to database 'powerdns' on '127.0.0.1'.\nJun 05 01:24:36 Done launching threads, ready to distribute questions<\/code><\/pre>\n\n\n\n<p>If you encounter any error, please fix it before you can proceed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Running PowerDNS<\/h3>\n\n\n\n<p>To start and enable PowerDNS to run on system boot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl start pdns\nsystemctl enable pdns<\/code><\/pre>\n\n\n\n<p>To check the status of PowerDNS,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl status pdns\n\u25cf pdns.service - PowerDNS Authoritative Server\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/pdns.service; enabled; vendor preset: disabled)\n   Active: active (running) since Wed 2019-06-05 01:29:33 EAT; 3min 9s ago\n     Docs: man:pdns_server(1)\n           man:pdns_control(1)\n           https:&#47;&#47;doc.powerdns.com\n Main PID: 4066 (pdns_server)\n    Tasks: 8 (limit: 2351)\n   Memory: 4.3M\n   CGroup: \/system.slice\/pdns.service\n           \u2514\u25004066 \/usr\/sbin\/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no<\/code><\/pre>\n\n\n\n<p>If FirewallD is running, allow DNS through it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --add-service=dns --permanent\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>You can verify that DNS port 53 is opened.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ss -altnp | grep 53\nLISTEN    0         128                0.0.0.0:53               0.0.0.0:*        users:((\"pdns_server\",pid=4066,fd=8))                                          \nLISTEN    0         128                   &#91;::]:53                  &#91;::]:*        users:((\"pdns_server\",pid=4066,fd=9))<\/code><\/pre>\n\n\n\n<p>Well, you have successfully installed PowerDNS with MariaDB configured as the backend. In our next guide, we will learn how to administer PowerDNS using the web based tool called Poweradmin. Enjoy<\/p>\n\n\n\n<p>Reference:<\/p>\n\n\n\n<p><a href=\"https:\/\/doc.powerdns.com\/authoritative\/installation.html\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Getting Started with PowerDNS (opens in a new tab)\">Getting Started with PowerDNS<\/a><\/p>\n\n\n\n<p>Other related Guides&#8217;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-setup-master-slave-dns-server-using-bind-on-centos-7\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Setup Master-Slave DNS Server using BIND on CentOS 7<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to install PowerDNS with MariaDB backend on Fedora 30\/29\/CentOS 7. PowerDNS is a powerful opensource DNS<\/p>\n","protected":false},"author":1,"featured_media":9314,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,971,972],"tags":[109,88,973,924,4309,975,974],"class_list":["post-2961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-dns","category-powerdns","tag-bind","tag-centos-7","tag-dns","tag-fedora-30","tag-install-powerdns-with-mariadb-backend-on-fedora-30-29-centos-7","tag-poweradmin","tag-powerdns","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2961"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=2961"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2961\/revisions"}],"predecessor-version":[{"id":11021,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2961\/revisions\/11021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9314"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}