DDNS with PowerDNS – server side

This is the second part in the “DDNS with PowerDNS” series. If you didn’t read the first post, which deals with the client setup (client is the computer who’s IP changes a lot), you can read it here: DDNS with PowerDNS – client side.

On the server side, we already have the IP of the client written in a file somewhere, by the script that runs on the client machine. Now all we need to do is take this IP and instruct the DNS server to use it when someone queries the hostname of the client.

The simplest idea is to run a script on a cron job and update DNS files, or record in a database. But since I use PowerDNS, the following solution is PowerDNS-specific.

PowerDNS has this nice feature, which allows you to pipe the DNS requests to an external program or script. This feature is explained in the backend details page, and they also provide a sample script, which I used as a template.

This is how we use the pipe system of PowerDNS:

  1. We tell PowerDNS, in the config file, that some queries need to be passed to the pipe backend.
  2. In the pipe script, we read the file that has the IP of our client host and provide the correct answer to the query.
  3. Anytime we need to change IP, we just overwrite that file.

Yes, that simple!

Step 1. First, let’s see what we need to change in the PowerDNS config in order to use the pipe backend. These are the relevant lines in /etc/powerdns/pdns.conf:

launch=pipe,bind
pipe-command=/path/to/ddns-pipe.pl
pipe-regex=^YOUR.FQDN.HOST.NAME;.*$

Of course, replace the path and YOUR.FQDN.HOST.NAME with the correct values. Make sure you don’t mess up the regex, it needs to have the ^ in front and ;.*$ at the end. And of course, FQDN hostnames only!

Note that the first line might be different to you, if you use another backend than bind. Make sure you edit it accordingly.

Step 2. Download ddns-pipe.pl and make it executable (make sure you place it in the correct path, the same that you wrote in pdns.conf). Also, make sure you edit the path to point to the correct IP file, and your host name ($domain and $ipfile). Remember – FQDN!

Step 3. Restart PowerDNS and that’s it! When PowerDNS receives a query for your hostname, it will forward it to the script, which will answer with the current IP. Updating it is really simple: we just overwrite the file (like we do in the first post of the series, DDNS with PowerDNS – client side).

Notes: The script might be improved to first validate that the IP is correct. Also, it now reads the file every time there’s a query. We could, for example, only read the file if its timestamp is different (it means it was updated), but I’m counting on the Linux FS cache to minimize I/O (and I’m also lazy and don’t know Perl that well, too).

Enjoy! ;)

TwitterFacebookLinkedInGoogle ReaderYahoo MessengerEmailGoogle GmailYahoo MailPrintShare

Related posts:

  1. DDNS with PowerDNS – client side
  2. How to make cron send remote email without a MTA on the server
  3. Xmail cu server IMAP Dovecot
  4. Shared hosting, VPS sau server dedicat?
  5. Convert Xmail to Dovecot users

Leave a Reply

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

*


+ five = 11

CommentLuv badge