My name is  
Jurgens du Toit.
Systems Developer.
Problem Solver.

About Me

Technology and Solving Problems are my passion. I'm a South African that loves my wife, life, and coding.

I'm writing a book!

The Logstash Config Guide

Buy it now on Leanpub

26 September 2013

A DIY Dynamic DNS service using Cloudflare

By Jurgens du Toit

DynDNS was always the dynamic IP service of choice, but I could never get it to work properly, and I was always stuck with their lame domain names as I’m too cheap to pay for their serivces.

Luckily services of all kinds, including DNS Providers, have caught on to the fact that people want API’s. If there’s an API to do DNS updates, I can script a solution.

Some of my domains run off of Cloudflare which needs to overwrite your DNS. And, hey presto, they have an API. So here it is:

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
curl https://www.cloudflare.com/api_json.html \
    -d 'a=rec_edit' \
    -d 'tkn=1234512345qweqwe1234512345' \
    -d 'id=12345' \
    -d 'email=jrgns@jrgns.net' \
    -d 'z=jrgns.net' \
    -d 'type=A' \
    -d 'name=home' \
    -d "content=$1" \
    -d 'service_mode=0' \
    -d 'ttl=3600'

Quick and dirty. This updates a domain (home.jrgns.net) with id 12345 with the IP address that’s passed as the first argument to the script. There’s a bunch of ways to get your external IP, my favourite is curl http://api.externalip.net/ip, but I just run this script as the postscript of my ddclient (which updates another service)

1
2
3
4
5
6
7
8
9
10
# /etc/ddclient.conf

protocol=dyndns2
use=web, web=myip.dnsomatic.com
ssl=yes
server=updates.someservice.com
login=mylogin@gmail.com
password='123456'
daemon=3600
postscript=/home/jrgns/bin/cloudflare_dynamic_dns.sh

I’m sure the same can be done with outer services such as Route 53? Has anyone tried something like this?

blog comments powered by Disqus