Skip to content

Instantly share code, notes, and snippets.

@ptasker
Last active February 10, 2025 21:01
Show Gist options
  • Save ptasker/0cc79d09a2dadab4474807c0665e0ceb to your computer and use it in GitHub Desktop.
Save ptasker/0cc79d09a2dadab4474807c0665e0ceb to your computer and use it in GitHub Desktop.
PowerDNS setup
#!/bin/bash
set -e # Exit on error
# disable resolved
sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
echo "Updating system packages..."
sudo apt update && sudo apt install -y curl gnupg lsb-release sqlite3
# Install PowerDNS Recursor
echo "Installing PowerDNS Recursor..."
sudo apt update && sudo apt install -y pdns-recursor
# Configure PowerDNS Recursor
echo "Configuring PowerDNS Recursor..."
sudo tee /etc/powerdns/recursor.conf > /dev/null <<EOL 6,8 All
local-address=0.0.0.0
allow-from=0.0.0.0/0
forward-zones=example.com=127.0.0.1:5300
loglevel=9
quiet=no
log-common-errors=yes
dnssec=off
EOL
# Restart and enable Recursor
sudo systemctl restart pdns-recursor
sudo systemctl enable pdns-recursor
# Install PowerDNS Authoritative Server with SQLite
echo "Installing PowerDNS Authoritative Server..."
sudo apt install -y pdns-server pdns-backend-sqlite3 sqlite3 net-tools
# Configure SQLite database
SQLITE_DB_PATH="/var/lib/powerdns/pdns.sqlite3"
echo "Setting up SQLite database at $SQLITE_DB_PATH..."
sudo mkdir -p /var/lib/powerdns
sudo sqlite3 $SQLITE_DB_PATH < ./pdns-sqlite.sql
sudo chown pdns:pdns $SQLITE_DB_PATH
sudo chmod 755 $SQLITE_DB_PATH
# Configure PowerDNS Authoritative Server
echo "Configuring PowerDNS Authoritative Server with SQLite..."
sudo tee /etc/powerdns/pdns.conf > /dev/null <<EOL
launch=gsqlite3
gsqlite3-database=$SQLITE_DB_PATH
local-address=127.0.0.1
local-port=5300
api=yes
api-key=supersecureapikey
webserver=yes
webserver-address=0.0.0.0
webserver-port=8081
webserver-allow-from=0.0.0.0/0
EOL
# Restart and enable Authoritative Server
sudo systemctl restart pdns
sudo systemctl enable pdns
sudo netstat -tulnp | grep pdns # Check that pdns services are up
echo "PowerDNS Recursor and Authoritative (SQLite) setup is complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment