Set up PowerDNS on Ubuntu 22.04: Best DNS-Related Software
In this guide on the Orcacore website, we intend to teach you How To Set up PowerDNS on Ubuntu 22.04. Also, you will learn to set up PowerAdmin on Ubuntu 22.04. This tutorial will give you an overview of how to Set up PowerDNS on Ubuntu 22.04.
PowerDNS or pdns is an open-source (GPL) software. It provides software to create authoritative DNS, Recursive DNS, DNS loading balancer, Debugging tools, and APIs to provision zones and records. A complete suite of DNS-related software that you can use for your company. Setting up PowerDNS on Ubuntu 22.04 is an excellent way to gain control over your DNS infrastructure.
Benefits of PowerDNS:
- Flexibility: PowerDNS supports various backend storage options, including databases like MariaDB, MySQL, PostgreSQL, and even simple text files. This allows you to choose the backend that best suits your needs and infrastructure.
- Scalability: Designed for high-performance environments, PowerDNS can handle a large number of DNS queries, making it suitable for both small and large networks.
- Security: PowerDNS supports DNSSEC, a suite of security extensions that adds cryptographic signatures to DNS data, ensuring the integrity and authenticity of DNS responses.
- Extensibility: PowerDNS has a modular architecture, allowing you to extend its functionality with custom scripts and plugins.
- Open Source: As an open-source project, PowerDNS benefits from a large community of developers and users, ensuring continuous improvement and support.
To complete this guide, log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04. This guide will teach you how to Set up PowerDNS on Ubuntu 22.04.
1. Install MariaDB For PowerDNS
In this guide, we use MariaDB as backend storage for PowerDNS zone files.
First, update your local package index with the following command:
sudo apt update
Then, use the following command to install the required packages and dependencies:
sudo apt install software-properties-common gnupg2 curl git -y
Now use the following command to install MariaDB on Ubuntu 22.04:
sudo apt install mariadb-server mariadb-client -y
Start and enable your MariaDB service:
# sudo systemctl start mariadb
# sudo systemctl enable mariadb
Create PowerDNS Database and User
At this point, you need to log in to your MariaDB shell by using the command below:
sudo mysql -u root
Then, from your MariaDB shell run the command below to create a PowerDNS database, here we named it powerdb
:
-- MariaDB [(none)]>
CREATE DATABASE powerdb;
Next, create a PowerDNS user and grant all the privileges to it. Here we named it poweruser
, remember to choose a strong password for:
-- MariaDB [(none)]>
GRANT ALL ON powerdb.* TO 'poweruser'@'%' IDENTIFIED BY 'password';
Finally, flush the privileges and exit from the MariaDB shell:
-- MariaDB [(none)]>
FLUSH PRIVILEGES;
-- MariaDB [(none)]>
EXIT
2. Disable systemd-resolved Service on Ubuntu 22.04
systemd-resolved is a system service that provides network name resolution to local applications. It implements a caching and validating DNS/DNSSEC stub resolver, as well as an LLMNR and MulticastDNS resolver and responder.
At this point, you need to disable and stop the systemd-resolved service by using the commands below:
# sudo systemctl stop systemd-resolved
# sudo systemctl disable systemd-resolved
Then, you need to remove the symbolic link for the /etc/resolv.conf
file by using the command below:
# ls -lh /etc/resolv.conf
#-rw-r--r-- 1 root root 102 Mar 16 08:10 /etc/resolv.conf
# sudo unlink /etc/resolv.conf
Next, use the following command to update the /etc/resolv.conf
:
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
3. Set up PowerDNS on Ubuntu 22.04
At this point, we will install PowerDNS from the APT repository.
To do this, you can use the command below:
sudo apt install pdns-server pdns-backend-mysql -y
When your installation is completed, you can configure your PowerDNS database.
4. Configure PowerDNS Database on Ubuntu 22.04
At this point, you need to import the PowerDNS database schema. To do this run the command below with the PowerDNS user and database that you have created before:
mysql -u poweruser -p powerdb < /usr/share/pdns-backend-mysql/schema/schema.mysql.sql
After the schema has been imported, you need to configure the PowerDNS connection details to the database. To do this, create and open a file with your favorite text editor, here we use the vi editor:
sudo vi /etc/powerdns/pdns.d/pdns.local.gmysql.conf
Add the following lines to the file with your PowerDNS database values:
# MySQL Configuration
# Launch gmysql backend
launch+=gmysql
# gmysql parameters
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-dbname=powerdb
gmysql-user=poweruser
gmysql-password=password
gmysql-dnssec=yes
# gmysql-socket=
When you are done, save and close the file.
Set the correct ownership and permission for the file:
# sudo chown pdns: /etc/powerdns/pdns.d/pdns.local.gmysql.conf
# sudo chmod 640 /etc/powerdns/pdns.d/pdns.local.gmysql.conf
Now you can verify your PowerDNS database connection on Ubuntu 22.04 by using the command below:
# sudo systemctl stop pdns.service
# sudo pdns_server --daemon=no --guardian=no --loglevel=9
In your output you will see:
Start and Enable PowerDNS Service
At this point, start and enable your PowerDNS service by using the following commands:
# sudo systemctl restart pdns
# sudo systemctl enable pdns
Check PowerDNS Port
Verify that port 53 is open for PowerDNS on Ubuntu 22.04:
sudo ss -alnp4 | grep pdns
Output
udp UNCONN 0 0 0.0.0.0:53 0.0.0.0:* users:(("pdns_server",pid=4402,fd=5))
tcp LISTEN 0 128 0.0.0.0:53 0.0.0.0:* users:(("pdns_server",pid=4402,fd=7))
You can also check if PowerDNS is responding to requests by using the command below:
dig @127.0.0.1
At this point, the installation of PowerDNS is completed, and you can proceed to the next step to install PowerDNS Admin on Ubuntu 22.04.
5. Install PowerDNS Admin on Ubuntu 22.04
With this Web-based admin tool, we can easily manage the PowerDNS server. To install PowerDNS admin, you need to install the Python development package and other required packages.
Install Required packages
First, use the following command to install the Python development package:
sudo apt install python3-dev -y
Then, install the required build tools:
sudo apt install libsasl2-dev libldap2-dev libssl-dev libxml2-dev libxslt1-dev libxmlsec1-dev libffi-dev pkg-config apt-transport-https virtualenv python3-venv build-essential libmariadb-dev git python3-flask -y
At this point, you need to install Node.js on Ubuntu 22.04. To do this, use the following commands:
# curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
# sudo apt install -y nodejs
Also, you need to have Yarn installed on your server. To do this, use the following commands to add the GPG key and repository and install Yarn:
# curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
# echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# sudo apt update
# sudo apt install yarn -y
Clone PowerDNS Admin Souce Code
At this point, you need to clone the PowerDNS admin source code on Ubuntu 22.04 by using the command below:
# sudo su -
# git clone https://github.com/ngoduykhanh/PowerDNS-Admin.git /var/www/html/pdns
Create a Virtual Environment
At this point, you need to switch to your /var/www/html/pdns/
directory and create a virtual environment by using the commands below:
# cd /var/www/html/pdns/
# virtualenv -p python3 flask
Activate the environment and install the libraries specified in the requirements.txt:
# source ./flask/bin/activate
# pip install --upgrade pip
# pip install -r requirements.txt
After that, use the following command to deactivate your environment:
deactivate
Now you need to configure the PowerDNS admin connectivity to your database.
Configure PowerDNS Admin Connection to PowerDNS Database
To do this, you need to edit the following file:
vi /var/www/html/pdns/powerdnsadmin/default_config.py
Find the lines below and change them to your PowerDNS database details:
### DATABASE CONFIG
SQLA_DB_USER = 'poweruser'
SQLA_DB_PASSWORD = 'password'
SQLA_DB_HOST = '127.0.0.1'
SQLA_DB_NAME = 'powerdb'
SQLALCHEMY_TRACK_MODIFICATIONS = True
....
When you are done, save and close the file.
Create a Database Schema
To do this, you can run the following commands step by step:
# cd /var/www/html/pdns/
# source ./flask/bin/activate
# export FLASK_APP=powerdnsadmin/__init__.py
# flask db upgrade
When you are finished, you should get an output similar to this:
Next, you need to generate the asset files using Yarn on Ubuntu 22.04:
# yarn install --pure-lockfile
# flask assets build
Last, deactivate your virtual environment:
deactivate
6. Enable PowerDNS API access on Ubuntu 22.04
At this point, you need to edit the following file to enable PowerDNS API access:
sudo vi /etc/powerdns/pdns.conf
Find the sections below and add the following lines shown below:
# api Enable/disable the REST API (including HTTP listener)
#
# api=no
api=yes
#################################
# api-key Static pre-shared authentication key for access to the REST API
#
# api-key=
api-key=2315d9cd-047e-4dc2-8fde-3efa9092aeed #You can generate one from https://codepen.io/corenominal/pen/rxOmMJ
When you are done, save and close the file.
Finally, restart PowerDNS on Ubuntu 22.04 to apply the changes:
sudo systemctl restart pdns
7. Create PowerDNS Admin Virtual Host File on Ubuntu 22.04
To complete this step, you need to install Nginx on your server:
sudo apt install nginx -y
Then, use the following command to create and open a PowerDNS virtual host file:
sudo vi /etc/nginx/conf.d/powerdns-admin.conf
Add the following content to the file:
server {
listen *:80;
server_name your-domain-name;
index index.html index.htm index.php;
root /var/www/html/pdns;
access_log /var/log/nginx/pdnsadmin_access.log combined;
error_log /var/log/nginx/pdnsadmin_error.log;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_redirect off;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
proxy_buffer_size 8k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_headers_hash_bucket_size 64;
location ~ ^/static/ {
include /etc/nginx/mime.types;
root /var/www/html/pdns/powerdnsadmin;
location ~* .(jpg|jpeg|png|gif)$ {
expires 365d;
}
location ~* ^.+.(css|js)$ {
expires 7d;
}
}
location / {
proxy_pass http://unix:/run/pdnsadmin/socket;
proxy_read_timeout 120;
proxy_connect_timeout 120;
proxy_redirect off;
}
}
When you are done, save and close the file.
Rename the default Nginx file with the command below:
sudo mv /etc/nginx/sites-enabled/default{,.old}
Check the syntax of your created file:
nginx -t
Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Next, set the correct ownership for the file:
sudo chown -R www-data: /var/www/html/pdns
Restart Nginx to apply the changes:
sudo systemctl restart nginx
8. Manage PowerDNS Admin on Ubuntu 22.04
To start and enable your service, you need to create a system unit file for PowerDNS Admin.
create and open the file with the following command:
sudo vi /etc/systemd/system/pdnsadmin.service
Add the following content to the file:
[Unit]
Description=PowerDNS-Admin
Requires=pdnsadmin.socket
After=network.target
[Service]
PIDFile=/run/pdnsadmin/pid
User=pdns
Group=pdns
WorkingDirectory=/var/www/html/pdns
ExecStart=/var/www/html/pdns/flask/bin/gunicorn --pid /run/pdnsadmin/pid --bind unix:/run/pdnsadmin/socket 'powerdnsadmin:create_app()'
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
When you are done, save and close the file.
Also, you need to create a socket file for PowerDNS Admin:
sudo vi /etc/systemd/system/pdnsadmin.socket
Add the following content to the file:
[Unit]
Description=PowerDNS-Admin socket
[Socket]
ListenStream=/run/pdnsadmin/socket
[Install]
WantedBy=sockets.target
when you are done, save and close the file.
Next, create an environment file:
# mkdir /run/pdnsadmin/
# echo "d /run/pdnsadmin 0755 pdns pdns -" >> /etc/tmpfiles.d/pdnsadmin.conf
Set the correct permissions for it:
# chown -R pdns: /run/pdnsadmin/
# chown -R pdns: /var/www/html/pdns/powerdnsadmin/
Finally, reload the system daemon:
sudo systemctl daemon-reload
Next, use the following commands to start and enable the PowerDNS Admin service on Ubuntu 22.04:
sudo systemctl enable --now pdnsadmin.service pdnsadmin.socket
Verify your PowerDNS Admin is active and running on your server:
#sudo systemctl status pdnsadmin.service
● pdnsadmin.service - PowerDNS-Admin
Loaded: loaded (/etc/systemd/system/pdnsadmin.service; enabled; vendor pre>
Active: active (running) since Thu 2023-03-16 08:45:32 UTC; 17s ago
TriggeredBy: ● pdnsadmin.socket
Main PID: 9831 (gunicorn)
Tasks: 2 (limit: 4575)
...
#sudo systemctl status pdnsadmin.socket
● pdnsadmin.socket - PowerDNS-Admin socket
Loaded: loaded (/etc/systemd/system/pdnsadmin.socket; enabled; vendor pres>
Active: active (running) since Thu 2023-03-16 08:45:32 UTC; 58s ago
Triggers: ● pdnsadmin.service
Listen: /run/pdnsadmin/socket (Stream)
CGroup: /system.slice/pdnsadmin.socket
...
9. Access PowerDNS Admin Web Interface
At this point, you can access your PowerDNS Admin web interface by typing your server’s IP or Domain name in your web browser:
http://domain_name
or
http://IP_address
Begin by creating the admin user account. With the required details provides, click register to create the account.
Create an Account
Account Details
Now login to the PowerDNS Admin interface using the created user credentials.
PwerDNS Admin Login
Next, you should provide the PowerDNS API URL to connect to PowerDNS and manage it. Then, click on the Save Settings button to save the changes.
Server Settings
Click on the Dashboard button. You should see the PowerDNS admin dashboard. There are many configurations you can make to your server using the PowerDNS admin web UI such as editing the domain templates, removing domains, managing user accounts, etc. You can view the history of activities performed as well.
Conclusion
PowerDNS and PowerDNS Admin are tools used for managing DNS services, which are essential for mapping domain names to IP addresses. At this point, you have learned to Set up PowerDNS and PowerDNS Admin on Ubuntu 22.04. Set up PowerDNS on Ubuntu 22.04 to control your domain name system server.
Please subscribe to us on Facebook, Twitter, and YouTube.
Hope you enjoy it. You may also like these articles:
Introduce Ubuntu 22.04 (Jammy Jellyfish)
How To Set up Gradle on Ubuntu 22.04
Install and Configure Adminer on Ubuntu 22.04
How To Change Hostname on Ubuntu 22.04
Apache Maven Ubuntu 22.04
Chkrootkit security scanner Ubuntu 22.04
Tesseract OCR Install Ubuntu 22.04
Alternative Solutions for Setting Up PowerDNS on Ubuntu 22.04
While the guide above details a robust method for setting up PowerDNS with a MariaDB backend and PowerDNS Admin, alternative solutions exist that might be more suitable depending on your specific needs and technical expertise. Here are two different ways to achieve a similar outcome:
1. Using PowerDNS with a PostgreSQL Backend and a Dockerized PowerDNS-Admin
This approach provides an alternative database backend and simplifies the deployment of PowerDNS-Admin using Docker.
Explanation:
-
PostgreSQL: PostgreSQL is another robust and reliable open-source relational database. Some administrators prefer it over MariaDB/MySQL for its advanced features, adherence to SQL standards, and generally different performance characteristics.
-
Dockerized PowerDNS-Admin: Docker allows you to run PowerDNS-Admin in a containerized environment, simplifying installation and management. This eliminates the need to install numerous Python packages and dependencies directly on your host system, improving portability and reducing potential conflicts.
Steps:
a. Install PostgreSQL:
```bash
sudo apt update
sudo apt install postgresql postgresql-contrib -y
```
b. Create PowerDNS Database and User in PostgreSQL:
```bash
sudo -u postgres psql
```
Inside the PostgreSQL shell:
```sql
CREATE DATABASE powerdb;
CREATE USER poweruser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE powerdb TO poweruser;
q
```
c. Install PowerDNS with PostgreSQL Backend:
```bash
sudo apt install pdns-server pdns-backend-pgsql -y
```
d. Import the PowerDNS database schema for PostgreSQL:
```bash
sudo -u postgres psql -d powerdb -f /usr/share/pdns-backend-pgsql/schema/schema.pgsql.sql
```
e. Configure PowerDNS for PostgreSQL:
```bash
sudo vi /etc/powerdns/pdns.d/pdns.local.gpgsql.conf
```
Add the following lines:
```
launch+=gpgsql
gpgsql-host=127.0.0.1
gpgsql-port=5432
gpgsql-dbname=powerdb
gpgsql-user=poweruser
gpgsql-password=password
gpgsql-dnssec=yes
```
f. Dockerized PowerDNS-Admin:
Instead of cloning the source code and creating a virtual environment, use a pre-built Docker image for PowerDNS-Admin. There are several available on Docker Hub. For instance, you can use the `ngoduykhanh/powerdns-admin` image.
First install docker
```bash
sudo apt update
sudo apt install docker.io -y
```
Then pull and run the container
```bash
docker pull ngoduykhanh/powerdns-admin
docker run -d -p 8080:8080 -e SQLA_DB_USER=poweruser -e SQLA_DB_PASSWORD=password -e SQLA_DB_HOST=127.0.0.1 -e SQLA_DB_NAME=powerdb --name pdns-admin ngoduykhanh/powerdns-admin
```
**Explanation of Docker command:**
* `docker pull ngoduykhanh/powerdns-admin`: Downloads the specified Docker image.
* `docker run -d`: Runs the container in detached mode (in the background).
* `-p 8080:8080`: Maps port 8080 on the host to port 8080 inside the container. Adjust if needed.
* `-e SQLA_DB_USER=poweruser`: Sets the environment variable `SQLA_DB_USER` inside the container.
* `-e SQLA_DB_PASSWORD=password`: Sets the environment variable `SQLA_DB_PASSWORD` inside the container.
* `-e SQLA_DB_HOST=127.0.0.1`: Sets the environment variable `SQLA_DB_HOST` inside the container.
* `-e SQLA_DB_NAME=powerdb`: Sets the environment variable `SQLA_DB_NAME` inside the container.
* `--name pdns-admin`: Assigns the name "pdns-admin" to the container.
* `ngoduykhanh/powerdns-admin`: Specifies the image to use for the container.
Now you can access PowerDNS-Admin via `http://your_server_ip:8080`. You won't need to perform the steps related to virtual environments, pip installations, or asset building.
2. Using a Simple Text File Backend for PowerDNS (for Small, Static Zones)
For very small setups with infrequently changing DNS records, using a text file backend can be a simpler option. This is not suitable for dynamic environments or large zones.
Explanation:
- Instead of relying on a database, PowerDNS reads zone data directly from text files formatted in the standard zone file syntax.
- This eliminates the need to install and configure a database server, simplifying the overall setup.
- However, managing zones becomes manual, requiring you to edit the text files directly.
Steps:
a. Install PowerDNS with the Text File Backend:
```bash
sudo apt install pdns-server pdns-backend-bind -y
```
b. Configure PowerDNS to use the Text File Backend:
```bash
sudo vi /etc/powerdns/pdns.conf
```
Modify the following settings:
```
launch+=bind
bind-config=/etc/powerdns/bindbackend.conf
```
c. Create the bindbackend.conf
file:
```bash
sudo vi /etc/powerdns/bindbackend.conf
```
Add the directories where your zone files will be stored:
```
zonefiles=/etc/powerdns/zones
```
d. Create the Zone Directory:
```bash
sudo mkdir /etc/powerdns/zones
```
e. Create a Zone File:
For example, create a zone file for `example.com`:
```bash
sudo vi /etc/powerdns/zones/example.com.db
```
Add the following content (replace with your actual records):
```
$TTL 3600
@ IN SOA ns1.example.com. admin.example.com. (
2024010101 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
3600 ) ; Minimum TTL
;
@ IN NS ns1.example.com.
ns1 IN A 192.168.1.10
www IN A 192.168.1.20
```
f. Restart PowerDNS:
```bash
sudo systemctl restart pdns
```
Important Considerations for the Text File Backend:
- Manual Management: Adding, modifying, or deleting records requires directly editing the text files. This can be error-prone.
- No Dynamic Updates: The text file backend doesn’t support dynamic updates or APIs.
- Performance: Suitable only for small zones. PowerDNS needs to parse the text files on each change or restart.
- Security: Ensure proper file permissions to prevent unauthorized modifications. The
pdns
user should have read access.
These alternative solutions offer different trade-offs in terms of complexity, flexibility, and scalability. Choose the method that best aligns with your requirements and technical capabilities. Set up PowerDNS on Ubuntu 22.04 with the method that is best suited for you.