0

Dynamic DNS with your Domain Name

Preface: I have a PowerDNS cluster with PowerAdmin as a front end setup for a couple of my domains. You’ll need this setup prior to being able to use the information below.

 

Note of thanks: The initial forms of the dynamic DNS updater and much assistance in getting the later forms working came from Kealper, a good friend of mine. http://kealper.com

 

Now, down to the fun stuff!

Contents

Why?

Well, I have a decent sized infrastructure that runs from my apartment, and wanted to be able to reliably access it by URL when remote.  I wanted to be able to use my own domain, without CNAME-ing records to one of the relatively odd/weird free dynamic DNS domains out there. Also, I like a challenge.

How?

As mentioned at the top of this article, the backed for this is a PowerDNS Cluster of 2 servers, one of which runs PowerAdmin as the front end.  For information on setting these up, see:

https://www.powerdns.com/

And:

http://www.poweradmin.org/

I took the provided ‘dynamic_update.php’ from PowerAdmin and modified it slightly into 2 files, one for updating the A record called ‘dynamicupdate.php’, and one for updating the AAAA record called ‘dynamicupdatev6.php’.

On a linux server at my apartment, I run a small program written in Go that makes a call to a file on the PowerAdmin server called ‘checkip.php’.  This file returns the IPv4 or IPv6 IP to the Go updater.  The Go updater then makes a request to both the A and AAAA record updater files and updates the database with the new IPs.

This updater does the following:

  • Runs a check to the DNSServer and DNSServerv6 addresses provided in the config file to determine the IPv4 and IPv6 Public IP addresses
  • Logs these addresses in the same directory that the updater was run from to “lastip” and “lastipv6” files respectively, if they have changed since the last check
  • If the IPs have changed, it runs an HTTP request to the dynamicupdate.php and dynamicupdatev6.php files on the PowerAdmin server.  These files then update the PowerDNS database.

OK, Really, Get to the Goods!

Ok, Ok, here we go.

On the Linux Server to which you’d like the Dynamic DNS record to point:

Download the Updater

I have the updater available in 2 formats, pre-compiled for CentOS 7 x64, and the raw .go file.

Precompiled can be found here:

http://downloads.tfmm.co/?dir=crondyn/compiled

Raw .go can be found here:

http://downloads.tfmm.co/?dir=crondyn/src

Create the config file

You’ll need a configall.json file located in the same directory you’re going to run the updater from, a sample is available here:

http://downloads.tfmm.co/?dir=crondyn

Assign Variables

Here’s a description of the variables used in the file, and how you should assign them:

  • Username – PowerAdmin Username of the User that owns the Domain you wish to update. Cannot be “admin”
  • Password – PowerAdmin Password for the above-named user
  • Hostname – Hostname A record to be updated, should be full hostname, for example “dynamic.example.com”
  • DNSServer – IPv4 Domain Name of your PowerAdmin server.  This is used to check the IPv4 address.
  • DNSServerv6 – IPv6 Domain Name of your PowerAdmin server. This is used to check the IPv6 Address, and can ONLY be reachable over IPv6.
  • Protocol – Protocol over which your PowerAdmin Server accepts connections, either: “https://” or “http://”.  I strongly reccomend using HTTPS as a username and password will be sent to the PowerAdmin server from the updater.

Setup the Cron Job

I use the following Cron, with the compiled updater and configall.json residing in /myscripts/

*/5 * * * * /myscripts/crondyn-x64-linux > /dev/null 2>&1

On the PowerDNS/PowerAdmin Server

Download the Files

You’ll need the following 3 files:

dynamicupdate.php
dynamicupdatev6.php
checkip.php

The 2 dynamic update files are very similar to the dynamic_update.php provided by PowerAdmin, with minor modifications to better suit this updater.  All of these files are available from:

http://downloads.tfmm.co/?dir=crondyn/webserver-files

You’ll need to put these in the same directory that PowerAdmin is served out of.

Wrap-up

That’s it, nothing too fancy.  This updater should update the IPv4 or IPv6 address if the server only runs on one of those stacks, however it may error when doing so.

The raw .go file can be compiled and ran on a Raspberry Pi as well, for those of you interested.

How does it work?

This updater does the following:

  • Runs a check to the DNSServer and DNSServerv6 addresses provided in the config file to determine the IPv4 and IPv6 Public IP addresses
  • Logs these addresses to “lastip” and “lastipv6” respectively, if they have changed since the last check
  • If the IPs have changed, it runs an HTTP request to the dynamicupdate.php and dynamicupdatev6.php files on the PowerAdmin server.  These files then update the PowerDNS database.

Questions? Ideas? Comment below.  I might not have an answer, but I’ll do what I can to figure it out.

tfmm

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.