CloudFlare Dynamic DNS Client in Ruby

Samuel Williams Monday, 04 November 2013

I've been using CloudFlare for quite a while now and generally found that it is a good service, even the free plans — my sites load faster for people around the world, especially since I host most of my content in New Zealand which has a high latency to practically everywhere.

I host a couple of local off-site backup servers connected using consumer-level internet connections, and the IP address occasionally changes. Fortunately, CloudFlare provides a comprehensive client API for accessing and updating DNS records. I was previously using ddclient, but found that it wasn't easy to get it working with CloudFlare1.

So, using the incredibly easy CloudFlare Ruby bindings, I created the CloudFlare DNS Update gem which can be used to update a DNS records.

To set up the tool to perform dyndns-like updates, make sure you have a recent version of Ruby (2.0+ is ideal), then install the cloudflare-dns-update gem:

$ gem install cloudflare-dns-update
Successfully installed cloudflare-dns-update
Parsing documentation for cloudflare-dns-update
1 gem installed

Then, you need to grab your CloudFlare email address and API key from the CloudFlare My Account page and setup the configuration:

$ cloudflare-dns-update -c
This configuration file appears to be new, we require some details.
CloudFlare Key: 8afbe6dea02407989af4dd4c97bb6e25
CloudFlare Email:
What zone do you want to modify? e.g. ''
DNS Zone:
Getting list of domains for
(0) A
(1) A
(2) A
(3) A
Which record to update? 1
What command to get content for record? e.g. 'curl'
Command to get latest IP address: curl

Once you've done this much, everything is saved and you can just run the command directly to update the remote record in CloudFlare's DNS servers.

Further Reading

  • Fixing ddclient to work with Cloudflare.
  • Comments

    Leave a comment

    Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g. <>.