Press "Enter" to skip to content

How to Install PowerDNS and PowerDNS-Admin on Debian Buster

Important note: this post is outdated, use the new one instead.

Hi! This is a script-guide to install Powerdns (authoritative) and Powerdns-Admin on Debian 10 (buster), for Debian 9 (stretch) see this old post. This is a quick way, see instructions below, here is the commented code for the impatient.

#!/bin/bash

# get script absolute path
MY_PATH="`dirname \"$0\"`"
MY_PATH="`( cd \"$MY_PATH\" && pwd )`"
if [ -z "$MY_PATH" ] ; then
          exit 1
fi

# upgrade system and install dependencies
apt-get update && apt-get -y upgrade
apt-get -y install software-properties-common dirmngr
apt-get -y install git python-pip

# install and prepare last stable mariadb version
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.liquidtelecom.com/repo/10.4/debian buster main'
apt-get update && apt-get -y install mariadb-server

# run the secure script to set root password, remove test database and disable remote root user login, you can safely accept the defaults and provide an strong root password when prompted
mysql_secure_installation
mysql -u root -p < ${MY_PATH}/sql01.sql # provide previously set password

# install powerdns and configure db parameters
apt-get -y install pdns-server pdns-backend-mysql
cp ${MY_PATH}/pdns.local.gmysql.conf /etc/powerdns/pdns.d/
vi /etc/powerdns/pdns.d/pdns.local.gmysql.conf # db configuration

# install dnsutils for testing, curl and finally PowerDNS-Admin
apt-get -y install python3-dev dnsutils curl
apt-get -y install -y default-libmysqlclient-dev python-mysqldb libsasl2-dev libffi-dev libldap2-dev libssl-dev libxml2-dev libxslt1-dev libxmlsec1-dev pkg-config
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo 'deb https://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/yarn.list
apt-get -y install apt-transport-https # needed for https repo
apt-get update
apt-get -y install yarn
git clone https://github.com/ngoduykhanh/PowerDNS-Admin.git /opt/web/powerdns-admin
cd /opt/web/powerdns-admin
pip install virtualenv
virtualenv -p python3 flask
. ./flask/bin/activate
pip install -r requirements.txt
mysql -u root -p < ${MY_PATH}/sql02.sql
cp config_template.py config.py
vi config.py # db configuration
export FLASK_APP=app/__init__.py
flask db upgrade
flask db migrate -m "Init DB"

# install/update nodejs, needed to use yarn
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
yarn install --pure-lockfile
flask assets build

# create systemd service file and activate it
cp ${MY_PATH}/powerdns-admin.service /etc/systemd/system/
systemctl daemon-reload
systemctl start powerdns-admin
systemctl enable powerdns-admin

# install nginx and configure site
apt-get -y install nginx
cp ${MY_PATH}/powerdns-admin.conf /etc/nginx/sites-enabled/
nginx -t && service nginx restart

# activate powerdns api, change api-key if needed
echo 'api=yes' >> /etc/powerdns/pdns.conf
echo 'api-key=789456123741852963' >> /etc/powerdns/pdns.conf
echo 'webserver=yes' >> /etc/powerdns/pdns.conf
echo 'webserver-address=0.0.0.0' >> /etc/powerdns/pdns.conf
echo 'webserver-allow-from=0.0.0.0/0,::/0' >> /etc/powerdns/pdns.conf
echo 'webserver-port=8081' >> /etc/powerdns/pdns.conf
service pdns restart

# now go to server_name url and create a first user account that will be admin
# log in
# configure api access on powerdns-admin
# enjoy

Installation notes

You can execute the executable file install.sh inside the zip file as root, or execute lines one by one from code above. Whatever method you use you should read this notes carefully in order to fully understand what is going on, also read comments in script, there could be useful tips there. I assume that yo have a minimum linux knowledge and that you are comfortable with the shell and command line utilities.

  1. Download and uncompress pdns-buster.zip anywhere in the server, then cd into pdns folder.
  2. Edit sql01.sql and modify the second line to set a secure password instead of the default one ‘mypassword’.
  3. Edit sql02.sql and modify the second line to set a secure password instead of the default one ‘mypassword’.
  4. Edit powerdns-admin.conf and modify the value of server_name to match the fqdn we want our pdnsadmin be served from.
  5. Execute install.sh script:
    • Set mariadb root password when prompted.
    • Provide mariadb root password to execute sql01.sql when prompted.
    • Edit /etc/powerdns/pdns.d/pdns.local.gmysql.conf db settings to match this ones:
      • user: pdnsuser
      • password: <the one provided in step 2>
      • host: localhost
      • db name: pdns
    • Provide mariadb root password to execute sql02.sql when prompted.
    • Edit /opt/web/powerdns-admin/config.py db settings to match this ones:
      • user: pdnsuser
      • password: <the one provided in step 2>
      • host: localhost
      • db name: pdns
  6. Enter web interface (domain provided in step 4) and click on create account to create the first account, thal will be an admin account.
  7. Log in into pdnsAdmin with the newly created account.
  8. Configure pdns api and pdns key, http://127.0.0.1:8081/ and the one provided at the end of the script.
  9. Enjoy!

13 Comments

  1. Alex
    Alex October 28, 2019

    I had to issue following command before your script installed without errors:
    apt-get build-dep python3-lxml

    • tat0
      tat0 October 29, 2019

      Hi, Thanks for the advise, I hope this helps anyone with any related error.

  2. tommy
    tommy November 4, 2019

    Does this work behind NAT aswell? 🙂

    • tat0
      tat0 November 5, 2019

      Surely, as long as you correctly forward port 53 to your internal server and add rules to your firewall if necessary. This works for most use cases.

  3. Wormaus
    Wormaus December 25, 2019

    Sorry, da gibt es kein ‘config_template.py’ zum kopieren, das fehlt …:

    (flask) root@—–:/opt/web/powerdns-admin# cp config_template.py config.py
    cp: cannot stat ‘config_template.py’: No such file or directory
    (flask) root@—–:/opt/web/powerdns-admin#

    root@—–:/opt/web# find . -name *template.py
    ./powerdns-admin/powerdnsadmin/models/domain_template.py
    ./powerdns-admin/flask/lib/python3.7/site-packages/mako/template.py
    root@—–:/opt/web#

    pdnsadmin kann ohne passendes config file natürlich auch nicht starten … (ansonsten scheint alles zu passen)

  4. leandro
    leandro December 29, 2019

    hi
    i have some problems
    cp: cannot stat ‘config_template.py’: No such file or directory
    Error: Could not import “app”.
    Usage: flask db migrate [OPTIONS]

    Error: Could not import “app”.

  5. Jim P
    Jim P December 31, 2019

    Trying to find the fix to get powerdns-admin to work your script is the closest I got to getting it to work. I can provide more info but am kind of new to this app. I did find this line that is been changed recently from your script and the source. The script failed to run for me. I got one error in the config.py part it did not set the file.
    On this page in git https://github.com/ngoduykhanh/PowerDNS-Admin/wiki/Running-PowerDNS-Admin-with-Systemd,-Gunicorn–and–Nginx it has the info that changed.
    In your script check the systemd configuration the “Exec start” line changed. In the source I think they renamed app folder to powerdnsadmin. Can you please check your script if it works today. The only part failing is powerdns-admin. If you can fix this for me I would be happy repay you for your efforts. Thank you again for automating this for us your script works great. I am confident your gonna fix this issue alot easier than me. I tried for a while prior to asking for help. Thanks in advance

  6. Alex
    Alex February 9, 2021

    Hey There

    what are the steps to update pdns-admin installed by this script? Could you maybe write an instruction or script for updating the pds-admin installation?

    Greetings,
    Alex

    • tat0
      tat0 February 26, 2021

      Hi, unfortunately I no longer maintain those pdns-admin I used to, so I do not have an installation where test it. Anyway by memory the procedure would be something like this:

      cd /opt/web/powerdns-admin
      git fetch
      # backup modified files (e.g. powerdnsadmin/default_config.py)
      git reset --hard
      git pull
      # restore modified files
      source ./flask/bin/activate
      pip install -r requirements.txt
      # db upgrade
      export FLASK_APP=powerdnsadmin/__init__.py
      flask db upgrade
      # regenerate asset files
      yarn install --pure-lockfile
      flask assets build
      deactivate
      chown -R pdns:pdns /opt/web/powerdns-admin/powerdnsadmin/static/
      # restart service

      These would be the steps to have PowerDNS-Admin updated. Do not forget to backup your system, database, and so on just in case things go wrong. Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *