---
title: "How to Set Up PowerDNS on Debian/Ubuntu Linux"
description: "Learn how to set up a DNS server that supports high-availability and redundancy with a PowerDNS installation on Ubuntu Linux!"
canonical: "https://adamtheautomator.com/powerdns/"
---

# How to Set Up PowerDNS on Debian/Ubuntu Linux

> Learn how to set up a DNS server that supports high-availability and redundancy with a PowerDNS installation on Ubuntu Linux!

Source: https://adamtheautomator.com/powerdns/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Set Up PowerDNS on Ubuntu Linux](https://adamtheautomator.com/wp-content/uploads/2022/01/How-to-Set-Up-PowerDNS-on-Ubuntu-Linux.jpg)

# How to Set Up PowerDNS on Ubuntu Linux

[![](https://secure.gravatar.com/avatar/572a248f516b6d0cd566cb44fdbd9336f30ef95aa0f6d78f118c1f47b1b6d6b7?s=192&d=mm&r=g)Arvid Larson](https://adamtheautomator.com/author/arvid-larson/)28 January 20229 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)[Networking](/tag/networking/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing and Configuring MariaDB Database](#installing-and-configuring-mariadb-database)
*   [Installing PowerDNS on Debian/Ubuntu Linux](#installing-powerdns-on-debian-ubuntu-linux)
*   [Creating Database and Import Database Schema for PowerDNS](#creating-database-and-import-database-schema-for-powerdns)
*   [Setting up PowerDNS with MariaDB Backend](#setting-up-powerdns-with-mariadb-backend)
*   [Creating DNS Zones on PowerDNS](#creating-dns-zones-on-powerdns)
*   [Verifying DNS Propagation](#verifying-dns-propagation)
*   [Conclusion](#conclusion)

Struggling to create a DNS server that supports high availability and redundancy, yet with powerful and modern features? [PowerDNS](https://www.powerdns.com/software.html) is the best solution. [PowerDNS](https://www.powerdns.com/software.html) (pdns) is free and open-source DNS server software for Unix-like operating systems.

In this article, you will learn how to install and configure [PowerDNS](https://doc.powerdns.com/authoritative/) with the MariaDB database on the Debian/Ubuntu Linux system.

Ready to have a fully functional DNS server? Jump right in!

## Prerequisites

This tutorial is a hands-on demonstration, be sure you have the following in place:

*   A Linux machine – This tutorial uses the latest Debian 11 Bullseye.
*   A user with root privileges.

## Installing and Configuring MariaDB Database

By default, PowerDNS supports many backends such as database backends ([PostgreSQL](https://www.postgresql.org) and [MySQL](https://www.mysql.com/)/[MariaDB](https://mariadb.org/)), bind zone files, and JSON APIs. In this tutorial, you’ll use the MariaDB database as the PowerDNS database backend.

1\. First, open your terminal and SSH to your server.

2\. Next, run the [`apt install`](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command below to install basic package dependencies (`software-properties-common` `dirmngr` `apt-transport-https`) to your system.

```bash
sudo apt install software-properties-common dirmngr apt-transport-https -y
```

3\. Run the below commands to add the MariaDB repository and GPG key to your system. The MariaDB repository configuration is saved at the `/etc/apt/sources.list.d/` directory, while the GPG key is saved at the `/etc/apt/trusted.gpg.` directory.

```bash
# Add MariaDB repository for Debian system
sudo add-apt-repository 'deb [arch=amd64,i386,arm64,ppc64el] https://mirror.23m.com/mariadb/repo/10.6/debian bullseye main'

# Add GPG key for MariaDB repository
wget -qO- https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/mariadb_release_signing_key.gpg
```

4\. Now, run the following commands to refresh the repository and install the package (`mariadb-server`).

The MariaDB service starts after installation on Debian and Ubuntu distributions and will automatically run at system boot/startup.

```bash
# refresh package index
sudo apt update

# install MariaDB database
sudo apt install mariadb-server -y
```

5\. Run the [`mysql_secure_installation`](https://mariadb.com/kb/en/mysql_secure_installation/) command below to secure your MariaDB installation. `mysql_secure_installation`

```bash
mysql_secure_installation
```

6\. Press Enter at the terminal screen when prompted to type the `root` password for MariaDB since the default MariaDB installation comes with no password.

![Securing MariaDB Deployment with the mysql\_secure\_installation](https://ata-proxy-cors-headers.adamtheautomator.workers.dev/?https://adamtheautomator.com/wp-content/uploads/2022/01/image-358.png)

Securing MariaDB Deployment with the mysql\_secure\_installation

7\. Enter **Y** at the prompt shown below to change the default authentication to **unix\_socket**.

![Changing the authentication to unix\_socket](https://adamtheautomator.com/wp-content/uploads/2022/01/image-359.png)

Changing the authentication to unix\_socket

8\. Enter **Y** again at the below prompt and type a new strong password for the MariaDB server.

![Setting up MariaDB Root Password](https://adamtheautomator.com/wp-content/uploads/2022/01/image-360.png)

Setting up MariaDB Root Password

9\. Now enter **Y** on the prompt shown below. The default MariaDB installation comes with the default anonymous user on the production level, so you must remove the anonymous user.

![Removing default anonymous user from MariaDB](https://adamtheautomator.com/wp-content/uploads/2022/01/image-361.png)

Removing default anonymous user from MariaDB

10\. On the next prompt, enter **Y** to disable the remote login for the root user. You must disallow the MariaDB `root` user to log in remotely from other servers for security reasons.

![Disabling remote login for the root user to the MariaDB server](https://adamtheautomator.com/wp-content/uploads/2022/01/image-362.png)

Disabling remote login for the root user to the MariaDB server

11\. Type **Y** again to delete the default test database and remove all access and permission.

![Removing default database test and all access and privileges to it](https://adamtheautomator.com/wp-content/uploads/2022/01/image-363.png)

Removing default database test and all access and privileges to it

12\. Lastly, type **Y** again to reload all tables privileges and apply new changes to the MariaDB server.

![Reloading tables privileges to apply new changes ](https://adamtheautomator.com/wp-content/uploads/2022/01/image-364.png)

Reloading tables privileges to apply new changes

Once all MariaDB configuration is complete, you’ll receive a confirmation message like the screenshot below.

![Confirming MariaDB Configuration is Complete](https://adamtheautomator.com/wp-content/uploads/2022/01/image-365.png)

Confirming MariaDB Configuration is Complete

## Installing PowerDNS on Debian/Ubuntu Linux

As you completed the MariaDB installation for the PowerDNS database backend, you’re ready to install PowerDNS packages. You will add the official PowerDNS repository and GPG key and install PowerDNS server packages.

To install the latest PowerDNS packages from the official repository:

1\. Run the below commands to add the PowerDNS repository and GPG key to your system.

```bash
# Download PowerDNS GPG Key
wget -qO- https://repo.powerdns.com/FD380FBB-pub.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/pdns.gpg

# Adding the PowerDNS Repository for Debian 11 Bullseye System
echo "deb [arch=amd64] http://repo.powerdns.com/debian bullseye-auth-45 main" | sudo tee /etc/apt/sources.list.d/pdns.list

# Adding the PowerDNS Repository for Ubuntu 20.04 System
echo "deb [arch=amd64] http://repo.powerdns.com/ubuntu focal-auth-45 main" | sudo tee /etc/apt/sources.list.d/pdns.list
```

Related:[How to Download Files with Python Wget](https://adamtheautomator.com/python-wget/)

2\. Next, create a new configuration file named `/etc/apt/preferences.d/pdns` with your preferred editor, then populate the file with the following configuration.

With the below configuration, any packages beginning with the name `pdns-` will automatically install from the PowerDNS repository (`repo.powerdns.com`) instead of the Debian/Ubuntu repository.

```powershell
# all packages with first name pdns- will be installed from the repo.powerdns.com repository
Package: pdns-*
Pin: origin repo.powerdns.com
Pin-Priority: 600
```

3\. Run the following commands to update and refresh repositories, then install the PowerDNS (`pdns-server`) and PowerDNS MariaDB/MySQL backend (`pdns-backend-mysql`).

After installation, the PowerDNS service (`pdns.service`) stats and is automatically enabled.

```bash
# refresh package index after adding new repository
sudo apt update

# install PowerDNS and PowerDNS MySQL/MariaDB backend
sudo apt install pdns-server pdns-backend-mysql -y
```

4\. Lastly, run the [`systemctl`](https://adamtheautomator.com/ubuntu-systemctl/) command below to verify the `status` of the PowerDNS service (`pdns.service`).

```bash
sudo systemctl status pdns.service
```

Related:[Controlling Systemd services with Ubuntu systemctl](https://adamtheautomator.com/ubuntu-systemctl/)

As you see below, the PowerDNS service is **active (running)** on the default TCP port **53** and is started as the **PowerDNS Authoritative Server**.

![Verifying the status of the PowerDNS service](https://adamtheautomator.com/wp-content/uploads/2022/01/image-366.png)

Verifying the status of the PowerDNS service

## Creating Database and Import Database Schema for PowerDNS

After installing PowerDNS, you’ll be setting up the MariaDB as a database backend for PowerDNS. To do so, you’ll create a new database and user, then import the PowerDNS database schema.

1\. Run the following command to log in to the MySQL shell as the user `root`. Enter your MariaDB root password when prompted.

```bash
mysql -u root -p
```

After you log in to the MySQL shell, you’ll get the welcome message like the screenshot below.

![Logging in to the MySQL shell as the user root](https://adamtheautomator.com/wp-content/uploads/2022/01/image-367.png)

Logging in to the MySQL shell as the user root

2\. Next, run the following queries to create a new database (`pdns`) with an admin username set as `pdnsadmin`.

```bash
# creating database named pdns
create database pdns;

# create user pdnsadmin and grant privileges to the database pdns
grant all on pdns.* to pdnsadmin@localhost identified by 'StrongPdnsPasswd';

# reload database privileges to apply new changes
flush privileges;

# exit from the MySQL shell
exit
```

![Creating a new database and admin user for the PowerDNS server](https://adamtheautomator.com/wp-content/uploads/2022/01/image-368.png)

Creating a new database and admin user for the PowerDNS server

3\. Run the following command to import the PowerDNS database schema to the `pdns` database. Make sure to type the correct password for the `pdnsadmin` user.

The default installation of PowerDNS MySQL backend includes the database schema, which is available at the `/usr/share/pdns-backend-mysql/schema/` directory.

```bash
# import the schema.mysql.sql to the pdns database
mysql -u pdnsadmin -p pdns < /usr/share/pdns-backend-mysql/schema/schema.mysql.sql
```

4\. Now, run the below [`mysqlshow`](https://dev.mysql.com/doc/refman/8.0/en/mysqlshow.html) command to verify the database schema of the `pdns` database. This command shows you all available tables on the `pdns` database.

```bash
# Check list of tables on the pdns database
mysqlshow pdns
```

Below, you can see the tables available on the **pdns** database.

![Checking database schema on the database (pdns)](https://adamtheautomator.com/wp-content/uploads/2022/01/image-369.png)

Checking database schema on the database (pdns)

## Setting up PowerDNS with MariaDB Backend

You’ve configured MariaDB and set up your database. But how do you know if PowerDNS is working? You’ll create a new MariaDB backend configuration for PowerDNS. PowerDNS service uses this configuration to connect to the MySQL database and store all DNS data on the database.

1\. Run the following command to `stop` the PowerDNS service (`pdns.service`) first before creating the PowerDNS backend configuration.

```bash
sudo systemctl stop pdns.service
```

2\. Next, create a file named _myself.conf_ in the _/etc/powerdns/pdns.d/_ directory with your text editor, and populate the file with the following configuration.

Change the database username and password with your information, and save the changes.

> _All additional configurations for PowerDNS must be saved in the `/etc/powerdns/pdns.d` directory._

```powershell
# Define the gmysql backend
launch+=gmysql

# Details MariaDB database for PowerDNS
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-dbname=pdns
gmysql-user=pdnsadmin
gmysql-password=StrongPdnsPasswd
gmysql-dnssec=yes
# gmysql-socket=
```

3\. Run the following commands to change the permission and ownership of the `mysql.conf` file. At this point, MySQL backend configuration for PowerDNS is created.

```bash
# change the ownership to user and group pdns
sudo chown pdns:pdns /etc/powerdns/pdns.d/mysql.conf

# change permission of the file
sudo chmod 640 /etc/powerdns/pdns.d/mysql.conf
```

4\. Now, run the following commands to start the PowerDNS service (`pdns.service`), and verify the service `status`.

```bash
# start PowerDNS service
sudo systemctl start pdns.service

# verify status of the PowerDNS service
sudo systemctl status pdns.service
```

If your PowerDNS configuration is correct, you’ll receive the following output showing the PowerDNS service status is `active (running)`.

![Verifying PowerDNS service status](https://adamtheautomator.com/wp-content/uploads/2022/01/image-370.png)

Verifying PowerDNS service status

5\. Finally, execute the below command to check the `syslog` file. This command lets you ensure the MySQL backend module is loaded to the PowerDNS server.

```bash
grep -rin pdns_server /var/log/syslog
```

![Checking PowerDNS log](https://adamtheautomator.com/wp-content/uploads/2022/01/image-371.png)

Checking PowerDNS log

## Creating DNS Zones on PowerDNS

PowerDNS provides a command-line utility called [`pdnsutil`](https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html) for managing [Zones](https://www.cloudflare.com/learning/dns/glossary/dns-zone/) and [DNSSEC](https://www.icann.org/resources/pages/dnssec-what-is-it-why-important-2019-03-05-en). The `pdnsutil` command can be run remotely to make changes to the PowerDNS backend database.

Related:[How to Manage DNS Zones With PowerShell](https://adamtheautomator.com/powershell-add-dns-zone/)

In this demo, you’ll create a new DNS zone for the `example.io` domain.

1\. Run the `pdnsutil` command below to create a new DNS zone (`create-zone`) named `example.io`.

```bash
pdnsutil create-zone example.io
```

2\. Next, execute the following commands to create a new nameserver and assign the nameserver to the PowerDNS server IP address.

```bash
# define ns1 A record to IP address 172.16.5.10
pdnsutil add-record example.io ns1 A 172.16.5.10

# define nameserver for example.io to the ns1.example.io
pdnsutil add-record example.io @ NS ns1.example.io
```

3\. Run the below command to add the new A record for the `example.io` domain. This domain will use the IP address `172.16.5.20`.

```bash
pdnsutil add-record example.io @ A 172.16.5.20
```

4\. Run the following commands to add new subdomains for your applications.

```bash
# add subdomain www
pdnsutil add-record example.io www A 172.16.5.20

# add subdomain storage with the target server 172.16.5.50
pdnsutil add-record example.io storage A 172.16.5.50
```

5\. Now, run the below command to add an MX record. The MX record handles email delivery for the main domain (`example.io`).

```bash
pdnsutil add-record example.io @ MX "10 example.io"
```

6\. Run the below commands to set `nano` as the default editor and open the `example.io` file.

```bash
# setup default editor on the system temporary
export EDITOR=nano

# edit DNS zone example.io manually
pdnsutil edit-zone example.io
```

Modify the default SOA record in the _example.io_ file with the configuration below. After doing so, save the changes and exit from the editor.

```powershell
example.io      3600    IN      SOA     ns1.example.io admin.example.io 0 10800 3600 604800 3600
```

![Setting up SOA record](https://adamtheautomator.com/wp-content/uploads/2022/01/image-372.png)

Setting up SOA record

7\. Type **a** and press Enter to confirm applying the new changes, as shown below.

![Applying new changes](https://adamtheautomator.com/wp-content/uploads/2022/01/image-373.png)

Applying new changes

8\. Now, run the following command to show all available DNS records on the `example.io` zone.

```bash
pdnsutil list-zone example.io
```

You can confirm below that the SOA record you modified (step six) reflects on the DNS records list.

![](https://adamtheautomator.com/wp-content/uploads/2022/01/image-374.png)

Checking available records on the DNS zone exmaple.io

9\. Lastly, run the below command to verify PowerDNS zones configuration.

```bash
pdnsutil check-all-zones
```

Below, you can see that there are seven records on the _example.io_ zone without any error and warning.

![Verifying zones configuration on PowerDNS](https://adamtheautomator.com/wp-content/uploads/2022/01/image-375.png)

Verifying zones configuration on PowerDNS

## Verifying DNS Propagation

You’ve successfully created the DNS zone for the _example.io_ domain, and that’s great! Now, you’ll verify the DNS propagation of the `example.io` domain using the [Domain Information Groper](https://linux.die.net/man/1/dig) (DIG) tool. The `dig` command is the DNS lookup tool that lets you verify DNS propagation and troubleshoot your DNS server.

1\. Run the following command to `install` the `dnsutils` package on your system.

> _The `dig` command is part of the `dnsutils` package._

```bash
sudo apt install dnsutils -y
```

2\. Next, run the `dig` command below to check the A record for the _example.io_ domain. In this example, the PowerDNS server IP address is `172.16.5.10`.

```bash
dig example.io @172.16.5.10
```

In the `ANSWER SECTION`, you’ll see a similar output as below.

![Verifying A record of example.io domain](https://adamtheautomator.com/wp-content/uploads/2022/01/image-376.png)

Verifying A record of _example.io_ domain

3\. Additionally, run the following commands to check another subdomain, such as `www.example.io` and `storage.example.io`.

```bash
# check subdomain www.example.io
dig www.example.io @172.16.5.10

# check subdomain storage.example.io
dig storage.example.io @172.16.5.10
```

Below, the `www.example.io` subdomain is resolved to the same server as the `example.io` domain.

![](https://adamtheautomator.com/wp-content/uploads/2022/01/image-377.png)

Verifying the _www.example.io_ subdomain

The `storage.example.io` subdomain is resolved to another server with an IP address of `172.16.5.50`, as shown below.

![Verifying the storage.example.io subdomain](https://adamtheautomator.com/wp-content/uploads/2022/01/image-378.png)

Verifying the _storage.example.io_ subdomain

4\. Lastly, run the `dig` command below to check the MX record for the _example.io_ domain.

> _You can also check other DNS records, such as `TXT`, `MX`, `SOA`, and so on._

```bash
dig MX example.io @172.16.5.10
```

![Verifying the MX record of the example.io domain](https://adamtheautomator.com/wp-content/uploads/2022/01/image-379.png)

Verifying the MX record of the _example.io_ domain

## Conclusion

Throughout this tutorial, you’ve learned how to set up PowerDNS and MariaDB database backend in Debian/Ubuntu Linux. You’ve also realized that PowerDNS lets you create and manage DNS servers with small resources, unlike other DNS server applications. Additionally, you’ve learned to check DNS configuration and propagation with the `dig` command.

How to take PowerDNS to the next level? Perhaps by adding the PowerDNS [`recursor`](https://doc.powerdns.com/recursor/performance.html#recursor-caches) to enable DNS cache and setting up [`dnsdist`](https://dnsdist.org/guides/serverselection.html) as the DNS load balancer? Now go nuts and start creating high-availability and distributed DNS servers.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowerdns%2F&text=How%20to%20Set%20Up%20PowerDNS%20on%20Ubuntu%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowerdns%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowerdns%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/08/All-the-Ways-to-Check-If-a-Port-is-Open-in-Linux.jpg)

### [All the Ways to Check If a Port is Open in Linux](/check-if-a-port-is-open-in-linux/)

Learn all the ways to check if a port is open in Linux and when you would use the various methods and techniques!

![](https://adamtheautomator.com/wp-content/uploads/2022/08/Discover-the-Many-Ways-to-Get-an-IP-Address-on-Linux.jpg)

### [Get an IP Address on Linux : Discover the Many Ways](/get-an-ip-address-on-linux/)

Discover the many ways and tools that are available to get an IP address in Linux and learn how to incorporate those tools into scripts!

![](https://adamtheautomator.com/wp-content/uploads/2022/07/How-to-Update-Ubuntu-IP-and-Hostname-via-Bash.jpg)

### [How to Update Ubuntu IP and Hostname via Bash](/change-linux-ip-hostname-bash-script/)

Discover and learn how to change a Linux IP and Hostname via a Bash script in this new tutorial by ATA Learning!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
