My name is Philipp C. Heckel and I write about nerdy things.

How-To: Your own dynamic DNS server (with PowerDNS & a MySQL backend)


How-To: Your own dynamic DNS server (with PowerDNS & a MySQL backend)

I was using and for a long time, and because I’m too cheap to buy the premium version for a simple service like this, I finally decided to set up my own dynamic DNS server for my various systems.

This is a short tutorial describing how I did it. It’s really not rocket science, so don’t expect too much.


1. Requirements

You need:

  • A publicly accessible server with root access
  • A domain and control to delegate DNS zones
  • About 30min of set up time

In this example/post:

  • Our new DNS server will be at
  • Its name will be
  • The new dynamic DNS zone will be named

2. Install PowerDNS & MySQL

Assuming that you’re running Ubuntu 16.04+, install MySQL (apt install mysql-server), then install PowerDNS as per instructions on their repo site. Note that the Ubuntu 16.04 upstream version is broken, as per this issue, so be sure to install at least version 4.0.1.

Then install the PowerDNS MySQL backend via apt install pdns-backend-mysql.

If everything goes as planned, this will set up the pdns database for you automatically (including user and password), so you don’t have to manually do that. If that does not happen, configure it in /etc/powerdns/pdns.d/pdns.local.gmysql.conf, so that it looks something like this:

Once you’ve configured it, you may want to start the service to see if it is working (systemctl start pdns.service). Given that it is not properly configured with a zone, it may actually fail here. Check journalctl -u pdns.service for details.

3. Add your DNS zone

With the MySQL backend, you can configure your zone completely via SQL tables (duh!). For our dynamic DNS server, the only relevant tables are and pdns.records. If you want to know more about the other tables, a detailed documentation of the schema and plugin can be found on the PowerDNS plugin documentation page.

For this example, we’re configuring as our DNS zone, so let’s add this domain to the table:

Once we’ve done this, the table should look like this (assuming you’re looking at it via phpMyAdmin):

If you know DNS, you know that there are different types of records that can be added to a zone. Our dynamic DNS zone is pretty simple. We just need two records to get started. Let’s add a SOA record to declare that this server is authoritative for our dynamic DNS domain (here: and our first dynamic A record (here: let’s assume our home network’s public IP address is

If you add other A records, this may look like this:

Side note: PowerDNS looks at the change_date column (not shown in screenshot) to determine whether its cache needs to be updated. Be sure to always update that column if you change a record, and also always update the SOA record serial (third part of the record, see above ... 1483141082 ...) when anything in the zone has changed. You’ll get outdated/invalid results if you don’t do this.

That’s all you need to configure PowerDNS. After restarting the service (systemctl restart pdns), you should be able to query the DNS server for the two records that you added:

4. Delegating the domain

So far we can only verify that our zone works locally, but we haven’t made the dynamic DNS domain known to the world. If you ask for any domain * via DNS, the nameserver of your domain will still feel responsible. To tell it to delegate all requests for to the our server (aka, we need to change some records in our domain’s DNS entries.

My domain is hosted with Hosteurope, so I had to log into their domain management system and add two entries:

The two records you see are to map an IP address to the DNS server domain ( A and to actually delegate the subdomain to this DNS server ( NS

Once these records are live (this may take a few hours), you should be able to resolve queries for the zone from any computer. It’s easiest to do this via the requests we ran before, but this time run it from your workstation (instead of the server itself):

5. Updating the DNS zone regularly

Now that the zone is live and can be queried from anywhere, all you need to do is keep it up-to-date. How you do that is of course up to you. I’ve set up a JSON-RPC API on my server (I also wrote a guide on how to do that) and I’m updating it through that.

Each of my clients/machines runs a simple script every 2 minutes in a cron job:

On the server, the API endpoint essentially runs these two queries for every host update request:

That’s essentially it. Your dynamic DNS server is ready to be used. PowerDNS really makes things incredibly easy for us. As always, leave notes and questions in the comments section.


  1. Kostas

    I made a relevant question there:

    Actually, my questions are:

    1) wouldn’t we need sth like the backends (namely BIND, to make it work?
    You used MySQL.
    2) I can see in this ( tutorial that BIND needs 2 servers to work (master-slave) otherwise the name resolution have validation problems, how this applies to powerdns?
    3) in terms of load balancing, will this solution fit in future or even just now so I can send the site visitors to other machines sitting at the background that actually host the sites?
    4) I rejected cpanel as it modifies the machine and is not simple to follow my idea of going “light” with minimum resources; what other alternatives do I have here?

    Very nice article indeed!
    Ps: I loved your json-rpc API!

  2. Jose


    I was found how to build my own DDNS and this is the answer. Thanks for your job!

    I have a question and this is that I have a problem after install the pdsn-backend-mysql annd it is that the file /etc/powerdns/pdns.d/pdns.local.gmysql.conf and I created it with vim, I started the service with no error but there is no new database into mysql server (I checked it by show databases;).

    Do you know what’s wrong?

    Thanks a lot.