Bored cat while you implement DDNS

Dynamic DNS with Cloudflare

By powersjo | Powersjo Technical Blog | 19 Mar 2022

This blog will show you how to use dynamic DNS with Cloudflare. The purpose of dynamic DNS, DDNS, is to update your public DNS provider in the case the service you host is behind a changing public IP. Without DDNS, once your public IP changes, the service behind that public IP won't be reachable via DNS. In this post after DDNS is setup with Cloudflare, I use ddclient on Ubuntu server. This will use an API key with Cloudflare to login and update the public IP I'm using for hosting to keep up to date.

Cloudflare Setup

In order to dynamically update the DNS record in Cloudflare, you must be able to login and make changes to your DNS record. This can be automated with ddclient and an API token. I used this guide here as a reference. First, login to Cloudflare > My profile > then API tokens.

Click on 'Create Token' and use the 'Edit zone DNS' template.

Select the zone, the appropriate domain and then click 'Continue to summary'. Select 'Create Token'.

Save the token for the Cloudflare API for reference later. This is essentially the servers password to change the DNS record.

You are also going to need your Cloudflare API Zone ID. I found this after going into my domain in Cloudflare and in the 'Overview', on the right hand column, scrolling all the way down.

ddclient on Ubuntu

Next step is to get back to a server to install ddclient to use that API token. In this example, I'm installing this on an Ubuntu server.

sudo apt install ddclient libdata-validate-ip-perl

For reference, I used this blog here to get me started. After the install completes, a script runs to configure the ddclient. I chose the 'other' DNS service provider.

I moved my ddclient.conf to /etc/ddclient/ and this is what it looks like. This is a slight change from my referenced document because instead of a login email, I use an API Zone ID. I believe at the time of this blog the ID is required, not the email. Note, the '#' symbol begins a comment.

# Configuration file for ddclient generated by debconf
# /etc/ddclient/ddclient.conf

syslog=yes  # log the output to syslog

## Global Config


login= ## Update Me with the API Zone ID
password= ## Update Me with your zone's cloudflare API Token
zone= ## Update Me with the domain ## Update Me with the subdomain

The above config didn't generate errors when I ran the following checks:

sudo service ddclient restart
sudo ddclient -query
sudo ddclient -daemon=0 -verbose -noquiet
sudo service ddclient status

Finally, you now have a DNS record that will be updated in Cloudflare in the case of a public IP change!

Check out my previous post here to learn about Lighttpd webserver on Ubuntu.

This post was originally from my blog, referenced below. 

You can get a 25 PRE token bonus if you use my referral code here. This is to support a decentralized web search engine with 

How do you rate this article?




Owner of a blogging site talking about books I have read, side projects, IT blogs, and military history.

Powersjo Technical Blog
Powersjo Technical Blog

This is meant to be a collection of technical blogs. The subjects covered are from my own learning and experience in IT.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.