So you got screwed over with the No-IP debacle and now you want to host your own DDNS service using CloudFlare. Easy right? Well apparently not. Here is how i did it with my Asus RT-N66U router running AsusWRT-Merlin firmware. The information below might also apply to DD-WRT, OpenWRT, or Tomato, but i can’t confirm this as i don’t have a router that supports those firmwares.
1) Your router needs to have a version of WGET that supports SSL.
This was the biggest hurdle i ran into. Out of the box, AsusWRT-Merlin only comes with a stripped down version of WGET that doesn’t support HTTPS links. To work around this, I had to install OPTWARE so that i could install WGET-SSL. After Optware is installed, just type in “ipkg wget-ssl install”. This will install a full version of wget into the /opt/bin folder.
You might also be able to use CURL (which is installed by default with OPTWARE) but i had trouble getting it to work with CloudFlare. Apparently the version of CURL that OPTWARE installs by default uses an outdated version of OpenSSL (0.9.7m) that doesn’t support SHA256. Every time i tried to hit CloudFlare’s API, it returned an error. So i just stuck with WGET-SSL.
2) Write a script that will update CloudFlare with your new IP.
To do this, i referenced this blog post to come up with a script that would work on AsusWRT-Merlin. The most import thing you need is the record ID of the A record you want to update. See the above linked blog post on how to obtain that ID. Once you have it, you can simply plug that info into my script. Here is the final script i came up with:
3) Save the above script in the /jffs/scripts folder and call it “dhcpc-event”
Before you can do this you will need to enable the JFFS section of the flash memory. Once that has been enabled, just save the above script into that location as a file called “dhcpc-event”. (I recommend using vi and doing it from the command line to avoid formatting issues)
As described in this wiki article, the dhcpc-event script is called whenever a DHCP event occurs on the WAN interface. This means any time your IP changes, this script will run. Which is exactly what we want it to do. When DHCP gives you a new IP, we want this script to update CloudFlare.
After you’ve created the script, be sure to set it to executable. (chmod a+rx dhcpc-event) Then test it by running it. (./dhcpc-event) Remember that the script has a 30 second pause at the beginning to ensure the WAN interface is fully up and operational before it does anything. So don’t worry when it just sits there for a while after you execute it. After 30 seconds, you should see a valid JSON response with the newly update IP listed in the “content” section. I recommend setting your A record to a bogus ip (E.g. 18.104.22.168) before testing the script. That way you can verify your script updated the record correctly.
And now you’re done. Anytime your IP changes, your router will call the script and update your IP. Again, this might work with DD-WRT or other firmwares, though i’m not sure of the specifics. If your firmware doesn’t have the dhcpc-event script like AsusWRT does, another option would be to simply create a script and then schedule it to run via CRON every hour or two. I’d definitely build in some checks to ensure you’re not constantly updating CloudFlare though. See this post for that info.