Automatic DNS Updater for Cloudflare Domains Hosted Behind a Dynamic IP

December 25, 2015 / 9:48 PM

Automatic DNS Updater for Cloudflare Domains Hosted Behind a Dynamic IP

devops
For those who host websites on a server behind a dynamic IP (e.g. a personally maintained server within a residential ISP), updating DNS records to reflect changes in the server's external IP address can be extremely tedious. Fortunately, all domains managed with CloudFlarecan use CloudFlare's client APIto query and update DNS records programmatically.
The CloudFlare DDNS Client(open sourced on GitHub) is a result of the ease of CloudFlare's API and the tedium associated with maunally updating DNS records and/or configuring finnicky third-party dynamic DNS services. You can read more about it in the README.
CloudFlare DDNS client screenshot
This client is intended to be installed on Linux servers behind a dynamic IP and run periodically with a predefined interval (e.g. with crontab). Depending on the update interval you specify, this effectively guarantees that your domain will never be down for more than that amount of time (due to an unexpected change in external IP address).
Full installation instructions are available in the README, but here's a quick rundown of how to get started:
  1. On the server, clone the repository, install necessary Python libraries, and install. (This assumes you already have Python and pip installed)
    git clone https://github.com/LINKIWI/cloudflare-ddns-client.git && cd cloudflare-ddns-client && sudo make install
  2. Configure the client. There will be interactive prompts for you to enter your email address, CloudFlare API key, and domains you want to update.
    cloudflare-ddns --configure
    After configuration, it would be in your favor to ensure that the update operation works as you expect, without errors.
    cloudflare-ddns --update-now
  3. Add a DNS update operation to crontab.
    crontab -e
    For example, if you want your DNS records to be updated at midnight every day, you would enter the following. This implies that, effectively, an external IP change would never impact connectivity to the server for more than 24 hours. You can make the update interval more or less aggressive as you see fit.
    0 0 * * * /usr/local/bin/cloudflare-ddns --update-now > /dev/null 2>&1
That's all you need to get started. You're welcome to visit the source codeor fork the repositoryin order to contribute.
Kevin Lin

Website

Github

Twitter