How to install PowerDNS via command line

June 17, 2024 / Domain and DNS

Installing PowerDNS via the command line on a Linux server involves numerous steps, including setting up a database backend (commonly MariaDB), configuring PowerDNS to use this backend, and confirming the service is running correctly. Below are the detailed steps to install PowerDNS on Ubuntu 18.04, 20.04, and 22.04.

Systematic Instructions:

  1. Update Your System:
    1. Ensure your package lists and system packages are up to date.
      sudo apt update
      sudo apt upgrade
  2. Install MariaDB:
    1. PowerDNS wants a database for storing DNS records. We will use MariaDB, which is compatible with MySQL.
      sudo apt install mariadb-server
    2. Secure your MariaDB installation-
      sudo mysql_secure_installation
  3. Create a Database for PowerDNS:
    1. Log in to MariaDB as the root user-
      sudo mysql -u root –p
    2. Create a database and user for PowerDNS-
      CREATE DATABASE powerdns;
      CREATE USER 'powerdnsuser'@'localhost' IDENTIFIED BY 'yourpassword';
      GRANT ALL PRIVILEGES ON powerdns.* TO 'powerdnsuser'@'localhost';
      FLUSH PRIVILEGES;
      EXIT;
  4. Install PowerDNS and MySQL Backend:
    1. Install PowerDNS and the MySQL backend-
      sudo apt install pdns-server pdns-backend-mysql
  5. Configure PowerDNS:
    1. Edit the PowerDNS configuration file to use the MySQL backend-
      sudo nano /etc/powerdns/pdns.conf
    2. Add the following lines:
      launch=gmysql
      gmysql-host=127.0.0.1
      gmysql-user=powerdnsuser
      gmysql-password=yourpassword
      gmysql-dbname=powerdns
  6. Import the PowerDNS Schema:
    PowerDNS provides a schema file to set up the necessary database tables. Import this schema into your PowerDNS database:

    sudo mysql -u root -p powerdns < /usr/share/doc/pdns-backend-mysql/schema.mysql.sql
  7. Start and Enable PowerDNS:
    Start the PowerDNS service and enable it to start at boot:

    sudo systemctl start pdns
    sudo systemctl enable pdns
  8. Verify PowerDNS Installation:
    Check the status of the PowerDNS service to ensure it is running correctly:
    sudo systemctl status pdns

    1. Additional Configuration (Optional)
      1. Firewall Configuration:
        If you have a firewall enabled, make sure to allow traffic on port 53, which is used for DNS queries:

        sudo ufw allow 53/tcp
        sudo ufw allow 53/udp
        sudo ufw reload
      2. Enable Logging:
        To enable logging for PowerDNS, you can modify the configuration file:

        sudo nano /etc/powerdns/pdns.conf
      3. Add or uncomment the following lines:
        log-dns-queries=yes
        loglevel=9
      4. Restart PowerDNS to apply the changes:
        sudo systemctl restart pdns

You have successfully installed and configured PowerDNS on your Ubuntu server. PowerDNS is now ready to serve DNS requests using the MySQL backend.

Spread the love