Dynamic DNS

How to use dynamic DNS with ddclient and Cloudflare
Saturday 5th of August 2017 01:59:58 AM

I wanted to start experimenting with some DevOps tools and wanted to try out some CI (Continuous Integration) frameworks/flows. Primary candidates for testing is Jenkins and TeamCity. I wanted to run a self hosted instance as I will focus on my private projects as a learning experience (also much for of a challenging adventure to set up the infrastructure yourself). Now I don't want to hog all the resources on my web-server, it's a pretty small VPS instance though very reasonable priced (at OVH) and I would like to keep it that way. It's already busy hosting multiple Laravel web projects, mysql, mongodb and a bunch of monitoring. Now I do have a Ubuntu server on my (somewhat messy) desk in my home office with plenty of horsepower. It's perfect for some CI application testing and more.

Dynamic DNS  
The first step for me to have a useful development/testing server would be to have access outside my home, and a domain name. I use Cloudflare for my webpage, where domain management is free. It turns out that they also support a customized version of ddclient, a linux client app that updates your A-record dns at your domain registrar. Here is the info provided from Cloudflare. They suggest you download a specific port of ddclient, that is a tar file of binary written in Perl. What I did on my Ubuntu 16.04 was to apt-get the ddclient, that way the package manager will install the necessary files (it needs perl-ssl libraries). I then copied the manually downloaded ddclient version that Cloudflare recommends over the one installed by apt. Honestly though I did not even test the one provided by default in Ubuntu, it might work as well.

After adding my conf settings I tried to run ddclient in debug mode, just like the guide recommends.

First issue:

FATAL:Error loading the Perl module JSON::Any needed for cloudflare update.
Someone on stackoverflow had the same issue, and a user had a response that worked for me:

sudo cpan install JSON::Any 

  I had never heard of cpan... guess it's a package manager for perl. 

The second issue:

WARNING:  unable to determine IP address

Found someone with the same issue on this blog. I noticed they had a line in their config that I had missed:

use=web, web=myip.dnsomatic.com

myip.dnsomatic.com is a webpage that returns your public ip adress. like "whatsmyipaddress.com" etc only a very simplistic pure text version.
I figued it would be a good idea to make my own little service like this, over ssl/https instead and it seemed to work just fine.
Feel free to use it: https://danielmellum.com/myip, comes with absolutely no warranty :)

use=web, web=https://danielmellum.com/myip

Finally I added ddclient as a service:

sudo update-rc.d ddclient enable
sudo service ddclient start

[email protected]:~/$ sudo service ddclient status
● ddclient.service - LSB: Update dynamic domain name service entries
   Loaded: loaded (/etc/init.d/ddclient; bad; vendor preset: enabled)
   Active: active (running) since Sat 2017-08-05 01:13:43 EDT; 25s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 17492 ExecStop=/etc/init.d/ddclient stop (code=exited, status=0/SUCCESS)
  Process: 17541 ExecStart=/etc/init.d/ddclient start (code=exited, status=0/SUCCESS)
    Tasks: 1
   Memory: 15.4M
      CPU: 154ms
   CGroup: /system.slice/ddclient.service
           └─17550 ddclient - sleeping for 580 second

Aug 05 01:13:43 UbuntuServer systemd[1]: Starting LSB: Update dynamic domain name service entries...
Aug 05 01:13:43 UbuntuServer systemd[1]: Started LSB: Update dynamic domain name service entries.

Now all that was left to do was some port-forwarding on my local router at home. I recommend to enable the firewall on your router and at your server. For Ubuntu UFW is pretty straight forward.

Next step would be to install docker and test some containers (perfect to quickly change applications/frameworks for experimentation).