An open collection of noteworthy things

Code

Using ddclient for DDNS with CloudFlare

DDclient is a perl client used to update Dynamic DNS entries (DDNS) so that your ip – 123.456.78.90 – can be translated to a domain name – wizgeek.co – even when it changes. Sadly, though, it didn’t work with CloudFlare. Until a while ago.

So let’s get down to it. SSH into whatever machine you want to use it with – for, example, a Raspberry Pi – and then run the following:

sudo apt-get install ddclient

Then, the patch and required packages:

sudo apt-get install curl sendmail libjson-any-perl libio-socket-ssl-perl
wget -O ddclient-cf-patch-3.8.1.patch "https://googledrive.com/host/0Bxw4R9RJ0ozIZGw1aWw3VlpZZkE"
sudo patch /usr/sbin/ddclient < ddclient-cf-patch-3.8.1.patch

Then we need to configure ddclient to use CloudFlare:

sudo nano /etc/ddclient.conf

Delete everything in there and add the following (if using PuTTY then just right click, if from a linux box Ctrl + Shift + V after copying to paste):

ssl=yes
use=web, web=dyndns
protocol=cloudflare, 
server=www.cloudflare.com, 
zone=mydomain.com, 
login=email@example.com, 
password=api-key 
host.mydomain.com

Okay, so here you’ll want to change the zone, the login, the password as well as the subdomain that you want to update. The “zone” is your domain, with no “www” or similar. The login is the email that you use to sign into CloudFlare, and the password is your API key which can be found here. Just scroll down and hit “view API key”. You will also need to change “host.mydomain.com” with the subdomain that you want to be attributed with your IP. Make sure that the record you’re updating is an A record.

You’re done! You can test your settings with:

sudo ddclient -daemon=0 -debug -verbose -noquiet

-It’ll print out everything it’s doing. If you get some kind of “Updated to xxx.xxx.xx.xx” then you’re good to go! If not, feel free to comment for some help!