Skip to content

Instantly share code, notes, and snippets.

@tehpeh
Last active August 6, 2023 14:16
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tehpeh/11274305 to your computer and use it in GitHub Desktop.
Save tehpeh/11274305 to your computer and use it in GitHub Desktop.
Dynamic DNS for Mac OS X with CloudFlare and ddclient

Update June 2019

The patch described below may no longer be necessary. CloudFlare instructions here. Perl module JSON::Any may still be required, however, see comments.

Description

Dyn's free dynamic DNS service will be ending on Wednesday, May 7th, 2014.

CloudFlare, however, has a little known feature that will allow you to update your DNS records via API or a command line script called ddclient. This will give you the same result, and it's also free.

Unfortunately, ddclient does not work with CloudFlare out of the box. There is a patch available and here is how to hack[1] it up on Mac OS X.

Requirements

Homebrew, basic command line skills, and a domain name that you own.

CloudFlare

Sign up to CloudFlare and add your domain name. Follow the instructions, the default values it gives should be fine.

You'll be letting CloudFlare host your domain so you need to adjust the settings at your registrar.

If you'd like to use a subdomain, add an 'A' record for it. Any IP address will do for now.

Let's get to business...

Installation

$ brew install ddclient

Patch

$ sudo cpan install JSON::Any
$ curl -O http://blog.peter-r.co.uk/uploads/ddclient-3.8.0-cloudflare-26-09-2013.patch
$ patch /usr/local/opt/ddclient/sbin/ddclient < ddclient-3.8.0-cloudflare-26-09-2013.patch

Config

$ cp /usr/local/opt/ddclient/share/doc/ddclient/sample-etc_ddclient.conf /usr/local/etc/ddclient/ddclient.conf
$ vim /usr/local/etc/ddclient/ddclient.conf

Add:

##
### CloudFlare (cloudflare.com)
###
ssl=yes
use=web, web=dyndns
protocol=cloudflare, \
server=www.cloudflare.com, \
zone=domain.com, \
login=you@email.com, \
password=api-key \
host.domain.com

Comment out:

#daemon=300

Your api-key comes from the account page
ssl=yes might already be in that file
use=web, web=dyndns will use dyndns to check IP (useful for NAT)

Start at boot

$ sudo cp -fv /usr/local/opt/ddclient/*.plist /Library/LaunchDaemons
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.ddclient.plist

You're done. Log in to https://www.cloudflare.com and check that the IP listed for your domain matches http://checkip.dyndns.com


[1] Don't do this in front of your boss.

@mkyung
Copy link

mkyung commented Jul 4, 2015

ddclient 3.8.3 officially supports cloudflare

http://sourceforge.net/p/ddclient/news/2015/05/ddclient-383-released/

@tomatohater
Copy link

Even though v3.8.3 does have CouldFlare support... I was getting the following error in syslog...

FATAL:    Error loading the Perl module JSON::Any needed for cloudflare update.

So I still had to install that @!#>@! Perl module....

sudo cpan install JSON::Any

Then after a little configuration magic... all is working smoothly.

@nodingneu
Copy link

When I run the patch part, I get

patch: **** Only garbage was found in the patch input.

@nodingneu
Copy link

The patch no longer exists:

$ curl http://blog.peter-r.co.uk/uploads/ddclient-3.8.0-cloudflare-26-09-2013.patch
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>

@nodingneu
Copy link

Anyone running into the above problem just check the latest patch version from: http://blog.peter-r.co.uk/cloudflare-ddclient-patch.html

@cscharff
Copy link

cscharff commented Dec 21, 2016

I believe you also need to specify a mechanism for determining and updating your external IP (lines 30-66 basically).

This works for me:
edit this line to remove the #

'# use=web, web=checkip.dyndns.org/
use=web, web=checkip.dyndns.org/
'

@nodingneu
Copy link

@tomatohater what configuration magic?

Because I currently have the same error message but have already installed JSON::Any

@grgar
Copy link

grgar commented Jun 6, 2017

@cscharff Uncommenting that is already mentioned in the gist.

@edbergavera
Copy link

@tomatohater

What did you do to solve the problem?

I already installed JSON::Any but still getting the error. I am using the latest ddclient version 3.8.3 from Homebrew.

@a0n
Copy link

a0n commented Aug 7, 2018

@anthonysomerset
Copy link

Latest version of ddclient from homebrew does NOT need the patch, if you are coming here off the back of dyndns issues then you might also want to try a web config line like this to avoid all dyndns/oracle dependencies:
use=web, web=v4.ident.me/

also latest guidance of homebrew install suggests you don't need to link the LaunchDaemon file either:

==> Downloading https://homebrew.bintray.com/bottles/ddclient-3.9.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring ddclient-3.9.0.mojave.bottle.tar.gz
==> Caveats
For ddclient to work, you will need to create a configuration file
in /usr/local/etc/ddclient, a sample configuration can be found in
/usr/local/opt/ddclient/share/doc/ddclient.

Note: don't enable daemon mode in the configuration file; see
additional information below.

The next reboot of the system will automatically start ddclient.

You can adjust the execution interval by changing the value of
StartInterval (in seconds) in /Library/LaunchDaemons/homebrew.mxcl.ddclient.plist,
and then

To have launchd start ddclient now and restart at startup:
  sudo brew services start ddclient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment