Created
March 27, 2025 05:04
-
-
Save radwebhosting/e64e4d827234c8140f9c5a0055c79cc3 to your computer and use it in GitHub Desktop.
Here's a Bash automation script to set up a PowerDNS Master server with a MySQL backend on Ubuntu 22.04+.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# PowerDNS Master Setup Script for Ubuntu | |
# === Configurable Variables === | |
DB_NAME="powerdns" | |
DB_USER="pdns" | |
DB_PASS="StrongPasswordHere" | |
MYSQL_ROOT_PASS="RootPasswordHere" | |
# === Update and install packages === | |
echo "[+] Updating system and installing packages..." | |
apt update && apt upgrade -y | |
apt install -y pdns-server pdns-backend-mysql mariadb-server wget curl unzip | |
# === Secure MySQL === | |
echo "[+] Securing MariaDB..." | |
mysql -u root <<EOF | |
ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASS'; | |
DELETE FROM mysql.user WHERE User=''; | |
DROP DATABASE IF EXISTS test; | |
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; | |
FLUSH PRIVILEGES; | |
EOF | |
# === Create PowerDNS Database === | |
echo "[+] Creating PowerDNS database and user..." | |
mysql -u root -p"$MYSQL_ROOT_PASS" <<EOF | |
CREATE DATABASE IF NOT EXISTS $DB_NAME; | |
CREATE USER IF NOT EXISTS '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS'; | |
GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost'; | |
FLUSH PRIVILEGES; | |
EOF | |
# === Download and import schema === | |
echo "[+] Downloading and importing PowerDNS schema..." | |
wget -q https://raw.githubusercontent.com/PowerDNS/pdns/master/modules/gmysqlbackend/schema/schema.mysql.sql -O /tmp/schema.mysql.sql | |
mysql -u $DB_USER -p"$DB_PASS" $DB_NAME < /tmp/schema.mysql.sql | |
# === Configure PowerDNS === | |
echo "[+] Configuring PowerDNS..." | |
PDNS_CONF="/etc/powerdns/pdns.conf" | |
sed -i 's/^launch=.*/launch=gmysql/' $PDNS_CONF | |
# Remove old gmysql lines if they exist | |
sed -i '/^gmysql-/d' $PDNS_CONF | |
# Append gmysql config | |
cat <<EOF >> $PDNS_CONF | |
# gmysql backend config | |
gmysql-host=127.0.0.1 | |
gmysql-user=$DB_USER | |
gmysql-password=$DB_PASS | |
gmysql-dbname=$DB_NAME | |
EOF | |
# === Restart PowerDNS === | |
echo "[+] Restarting PowerDNS..." | |
systemctl restart pdns | |
systemctl enable pdns | |
# === Done === | |
echo "" | |
echo "✅ PowerDNS Master setup is complete." | |
echo "You can now add DNS zones directly into the '$DB_NAME' database." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
📦 Usage
sudo
:📌 Notes
StrongPasswordHere
andRootPasswordHere
with real passwords before running.