UbuntuUbuntu Based

How To Install PowerDNS on Ubuntu 24.04 LTS

Install PowerDNS on Ubuntu 24.04

PowerDNS stands as one of the most robust and scalable DNS server solutions available today. Built with performance and flexibility in mind, this open-source authoritative nameserver offers enterprise-grade features that make it an ideal choice for web hosting providers, ISPs, and organizations requiring reliable DNS infrastructure. Ubuntu 24.04 LTS “Noble Numbat” provides the perfect foundation for deploying PowerDNS, combining long-term stability with cutting-edge technology support.

This comprehensive guide walks you through every step of installing PowerDNS on Ubuntu 24.04 LTS, from initial system preparation to advanced configuration options. Whether you’re a system administrator looking to replace traditional DNS servers like BIND or a developer seeking to implement custom DNS solutions, this tutorial provides the knowledge and practical steps needed for successful deployment.

Understanding PowerDNS Architecture

PowerDNS differs significantly from traditional DNS servers through its modular architecture and database-driven approach. The system separates the DNS server daemon from data storage, allowing for flexible backend configurations including MySQL, MariaDB, PostgreSQL, and SQLite databases. This separation enables powerful features like dynamic DNS updates, programmatic zone management, and seamless integration with existing infrastructure.

The PowerDNS ecosystem includes two primary components: the PowerDNS Authoritative Server for hosting DNS zones and the PowerDNS Recursor for recursive DNS resolution. For most installations, the Authoritative Server meets the requirements for hosting DNS records and managing domain resolution.

Prerequisites and System Requirements

Before beginning the PowerDNS installation process, ensure your Ubuntu 24.04 LTS system meets the following requirements:

Hardware Specifications:

  • Minimum 1GB RAM (2GB recommended for production)
  • At least 1 CPU core (2+ cores for high-traffic environments)
  • 10GB available disk space
  • Reliable network connectivity

Software Prerequisites:

  • Fresh Ubuntu 24.04 LTS installation
  • Root or sudo administrative privileges
  • Basic familiarity with Linux command line operations
  • Understanding of DNS concepts and networking principles

Begin by updating your Ubuntu system to ensure all packages are current:

sudo apt update && sudo apt upgrade -y

Install essential build tools and dependencies that PowerDNS requires:

sudo apt install curl wget gnupg2 software-properties-common apt-transport-https ca-certificates -y

Configure your system timezone to ensure accurate logging and DNS operations:

sudo timedatectl set-timezone UTC

Database Backend Installation and Configuration

PowerDNS requires a database backend to store DNS zones and records. MariaDB provides excellent performance and compatibility for PowerDNS installations.

Installing MariaDB Server

Install MariaDB server and client packages:

sudo apt install mariadb-server mariadb-client -y

Start and enable MariaDB service for automatic startup:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure your MariaDB installation by running the security script:

sudo mysql_secure_installation

Follow the prompts to:

  • Set a strong root password
  • Remove anonymous users
  • Disable remote root login
  • Remove test database
  • Reload privilege tables

Creating PowerDNS Database and User

Log into MariaDB as the root user:

sudo mysql -u root -p

Create a dedicated database for PowerDNS:

CREATE DATABASE powerdns CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create a PowerDNS user with appropriate privileges:

CREATE USER 'powerdns'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON powerdns.* TO 'powerdns'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Security Note: Replace your_secure_password with a strong, unique password. Consider using a password generator to create a secure credential.

Setting Up PowerDNS Database Schema

Download the PowerDNS MySQL schema file:

wget https://raw.githubusercontent.com/PowerDNS/pdns/master/modules/gmysqlbackend/schema.mysql.sql

Import the database schema:

mysql -u powerdns -p powerdns < schema.mysql.sql

Verify the table structure was created successfully:

mysql -u powerdns -p -e "SHOW TABLES;" powerdns

You should see tables including domains, records, cryptokeys, and others essential for PowerDNS operation.

PowerDNS Installation Methods

Ubuntu 24.04 LTS offers multiple approaches for installing PowerDNS, each with distinct advantages.

Installing from Official PowerDNS Repository

The official PowerDNS repository provides the latest stable versions with regular security updates. This method ensures access to cutting-edge features and optimal compatibility.

Create the keyring directory for PowerDNS repository keys:

sudo install -d /etc/apt/keyrings

Add the PowerDNS repository signing key:

curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo tee /etc/apt/keyrings/auth-49-pub.asc

Create the PowerDNS repository configuration file:

sudo nano /etc/apt/sources.list.d/pdns.list

Add the following repository configuration for Ubuntu 24.04 Noble:

deb [signed-by=/etc/apt/keyrings/auth-49-pub.asc] http://repo.powerdns.com/ubuntu noble-auth-49 main

Configure package pinning to prioritize PowerDNS repository packages:

sudo nano /etc/apt/preferences.d/auth-49

Add the pinning configuration:

Package: pdns-*
Pin: origin repo.powerdns.com
Pin-Priority: 600

Update package repositories and install PowerDNS:

sudo apt update
sudo apt install pdns-server pdns-backend-mysql -y

Installing from Ubuntu Repositories

For environments requiring standard Ubuntu-supported packages, install PowerDNS directly from Ubuntu repositories:

sudo apt install pdns-server pdns-backend-mysql -y

This method provides stability but may offer older PowerDNS versions compared to official repositories.

Verification of Installation

Confirm PowerDNS installation success:

pdns_server --version

Check installed packages and dependencies:

dpkg -l | grep pdns

Verify service status:

sudo systemctl status pdns

PowerDNS Configuration

Proper configuration ensures PowerDNS operates efficiently and securely within your environment.

Basic PowerDNS Configuration

The primary PowerDNS configuration file resides at /etc/powerdns/pdns.conf. Create a backup before making changes:

sudo cp /etc/powerdns/pdns.conf /etc/powerdns/pdns.conf.backup

Edit the configuration file:

sudo nano /etc/powerdns/pdns.conf

Add essential configuration parameters:

# Database Configuration
launch=gmysql
gmysql-host=127.0.0.1
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=your_secure_password

# Server Configuration
local-address=0.0.0.0
local-port=53
security-poll-suffix=

# API Configuration
api=yes
api-key=your_api_key_here
webserver=yes
webserver-address=127.0.0.1
webserver-port=8081
webserver-allow-from=127.0.0.1

# Logging
loglevel=4
log-dns-details=yes
log-dns-queries=yes

Advanced Configuration Options

For production environments, consider these additional configuration parameters:

# Performance Tuning
max-tcp-connections=20
receiver-threads=1
distributor-threads=3
signing-threads=3

# Security Settings
allow-axfr-ips=
disable-axfr=yes
guardian=yes
setuid=pdns
setgid=pdns

# Cache Settings
cache-ttl=20
negquery-cache-ttl=60
query-cache-ttl=20

Service Management

Test PowerDNS configuration syntax:

sudo pdns_server --config-name= --config-dir=/etc/powerdns --daemon=no --guardian=no --loglevel=9

If configuration validates successfully, start PowerDNS service:

sudo systemctl start pdns
sudo systemctl enable pdns

Monitor service status and logs:

sudo systemctl status pdns
sudo journalctl -u pdns -f

Testing PowerDNS Installation

Comprehensive testing ensures your PowerDNS installation functions correctly.

Basic Functionality Tests

Test DNS resolution using the dig command:

dig @localhost version.bind chaos txt

This query should return PowerDNS version information, confirming successful installation.

Test PowerDNS API functionality:

curl -X GET http://localhost:8081/api/v1/servers/localhost \
  -H "X-API-Key: your_api_key_here"

Creating Test DNS Records

Add a test domain to PowerDNS database:

INSERT INTO domains (name, type) VALUES ('example.local', 'NATIVE');

Create basic DNS records:

INSERT INTO records (domain_id, name, type, content, ttl) 
VALUES (1, 'example.local', 'SOA', 'ns1.example.local hostmaster.example.local 1 3600 1800 604800 86400', 86400);

INSERT INTO records (domain_id, name, type, content, ttl) 
VALUES (1, 'example.local', 'NS', 'ns1.example.local', 86400);

INSERT INTO records (domain_id, name, type, content, ttl) 
VALUES (1, 'ns1.example.local', 'A', '192.168.1.100', 86400);

Test record resolution:

dig @localhost example.local SOA
dig @localhost example.local NS
dig @localhost ns1.example.local A

Performance Monitoring

Monitor PowerDNS performance and resource usage:

# View active connections
ss -tuln | grep :53

# Monitor resource usage
top -p $(pgrep pdns_server)

# Check query statistics
sudo pdns_control show "*"

PowerDNS Admin Web Interface Installation

PowerDNS Admin provides a user-friendly web interface for managing DNS zones and records.

Installing Dependencies

Install Python development environment and required packages:

sudo apt install python3-pip python3-venv python3-dev libmysqlclient-dev build-essential libssl-dev libffi-dev libxml2-dev libxslt1-dev -y

Install Node.js for frontend dependencies:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs -y

PowerDNS Admin Installation

Create a dedicated user for PowerDNS Admin:

sudo useradd -r -d /opt/powerdns-admin -s /bin/bash pdnsadmin
sudo mkdir -p /opt/powerdns-admin
sudo chown pdnsadmin:pdnsadmin /opt/powerdns-admin

Switch to the PowerDNS Admin user and create a virtual environment:

sudo -u pdnsadmin bash
cd /opt/powerdns-admin
python3 -m venv venv
source venv/bin/activate

Install PowerDNS Admin via pip:

pip install --upgrade pip
pip install PowerDNS-Admin

Create PowerDNS Admin configuration file:

nano config.py

Add configuration parameters:

import os

# Database Configuration
SQLALCHEMY_DATABASE_URI = 'mysql://powerdnsadmin:admin_password@localhost/powerdnsadmin'

# PowerDNS Configuration
PDNS_STATS_URL = 'http://127.0.0.1:8081'
PDNS_API_KEY = 'your_api_key_here'
PDNS_VERSION = '4.9'

# Security Configuration
SECRET_KEY = 'your_secret_key_here'
BIND_ADDRESS = '127.0.0.1'
PORT = 9191

# Session Configuration
PERMANENT_SESSION_LIFETIME = 3600

Initialize PowerDNS Admin database:

export FLASK_APP=powerdnsadmin
flask db upgrade

Web Server Configuration

Install and configure Nginx as a reverse proxy:

exit  # Exit pdnsadmin user session
sudo apt install nginx -y

Create Nginx virtual host configuration:

sudo nano /etc/nginx/sites-available/powerdns-admin

Add the following configuration:

server {
    listen 80;
    server_name your_domain.com;
    
    location / {
        proxy_pass http://127.0.0.1:9191;
        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_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/powerdns-admin /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Create systemd service for PowerDNS Admin:

sudo nano /etc/systemd/system/powerdns-admin.service

Add service configuration:

[Unit]
Description=PowerDNS Admin
After=network.target

[Service]
Type=simple
User=pdnsadmin
Group=pdnsadmin
WorkingDirectory=/opt/powerdns-admin
Environment=PATH=/opt/powerdns-admin/venv/bin
ExecStart=/opt/powerdns-admin/venv/bin/python3 -m powerdnsadmin
Restart=always

[Install]
WantedBy=multi-user.target

Start and enable PowerDNS Admin service:

sudo systemctl daemon-reload
sudo systemctl start powerdns-admin
sudo systemctl enable powerdns-admin

Security Hardening and Best Practices

Implementing proper security measures protects your PowerDNS installation from threats and unauthorized access.

Firewall Configuration

Configure UFW firewall to allow only necessary ports:

sudo ufw enable
sudo ufw allow 22/tcp    # SSH
sudo ufw allow 53/tcp    # DNS TCP
sudo ufw allow 53/udp    # DNS UDP
sudo ufw allow 80/tcp    # HTTP (if using web interface)
sudo ufw allow 443/tcp   # HTTPS (if using SSL)

For production environments, restrict administrative access:

sudo ufw allow from your_admin_ip to any port 8081

PowerDNS Security Settings

Implement additional security measures in PowerDNS configuration:

# Disable zone transfers by default
allow-axfr-ips=
disable-axfr=yes

# Enable query logging for security monitoring
log-dns-queries=yes
log-dns-details=yes

# Restrict API access
webserver-allow-from=127.0.0.1,your_admin_network

# Enable guardian process for automatic restart
guardian=yes

Database Security

Secure MariaDB configuration:

# Remove unnecessary users
mysql -u root -p -e "DELETE FROM mysql.user WHERE User='';"

# Disable remote root access
mysql -u root -p -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"

# Set secure file permissions
sudo chmod 600 /etc/mysql/mariadb.conf.d/50-server.cnf

Implement regular backup procedures:

# Create backup script
cat > /opt/backup-powerdns.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/backup/powerdns"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
mysqldump -u powerdns -p powerdns > $BACKUP_DIR/powerdns_$DATE.sql
find $BACKUP_DIR -name "*.sql" -mtime +7 -delete
EOF

chmod +x /opt/backup-powerdns.sh

Troubleshooting Common Issues

Understanding common PowerDNS installation and configuration problems helps resolve issues quickly.

Installation Problems

Repository key verification failures:

# Re-add repository key
sudo rm /etc/apt/keyrings/auth-49-pub.asc
curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo tee /etc/apt/keyrings/auth-49-pub.asc
sudo apt update

Package dependency conflicts:

# Clean package cache and retry
sudo apt clean
sudo apt autoclean
sudo apt install -f

Configuration and Runtime Issues

Database connection failures:

# Test database connectivity
mysql -u powerdns -p -h localhost powerdns -e "SELECT 1;"

# Check PowerDNS logs for specific errors
sudo journalctl -u pdns -n 50

Service startup failures:

# Test configuration syntax
sudo pdns_server --config-dir=/etc/powerdns --daemon=no --guardian=no --loglevel=9

# Check for port conflicts
sudo netstat -tlnp | grep :53

DNS resolution problems:

# Verify PowerDNS is listening on correct interfaces
sudo ss -tlnp | grep pdns

# Test with verbose dig output
dig @localhost example.com +trace +short

Performance Optimization

Monitor and optimize PowerDNS performance:

# View PowerDNS statistics
sudo pdns_control show

# Monitor query patterns
sudo tcpdump -i any port 53

# Analyze log patterns
sudo grep "questions/sec" /var/log/syslog

Advanced Configuration Topics

DNSSEC Implementation

Enable DNSSEC for enhanced DNS security:

# Add to pdns.conf
dnssec=yes
default-ksk-algorithm=ecdsa256
default-zsk-algorithm=ecdsa256

Generate DNSSEC keys for domains:

sudo pdnsutil secure-zone example.com
sudo pdnsutil show-zone example.com

API Integration and Automation

PowerDNS REST API enables programmatic zone management:

# Create zone via API
curl -X POST http://localhost:8081/api/v1/servers/localhost/zones \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"name": "newdomain.com", "kind": "Native"}'

# Add DNS record via API
curl -X PATCH http://localhost:8081/api/v1/servers/localhost/zones/newdomain.com \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"rrsets": [{"name": "www.newdomain.com", "type": "A", "records": [{"content": "192.168.1.10", "disabled": false}]}]}'

Monitoring and Alerting

Implement comprehensive monitoring:

# Install monitoring tools
sudo apt install prometheus-node-exporter -y

# Configure PowerDNS metrics endpoint
echo "carbon-ourname=powerdns-server" >> /etc/powerdns/pdns.conf
echo "carbon-server=127.0.0.1:2003" >> /etc/powerdns/pdns.conf

Create alerting rules for critical DNS metrics:

# Monitor DNS query success rate
# Monitor zone transfer status
# Track database connection health
# Alert on service downtime

Congratulations! You have successfully installed PowerDNS. Thanks for using this tutorial for installing PowerDNS on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official PowerDNS website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button