DDNS using Cloudflare's API

There seem to be few DDNS services but either they are paid or they have quite a lot of restrictions, so using this simple guide you can automatically/dynamically change the IP address of a domain on cloudflare.

Now log into your cloudflare account and go to My profile -->API Tokens -->Global API Key, then copy the Key after entering your cloudflare's password, we will be needing it soon.

I ran this on my raspberry Pi 4, works pretty well

Code:
sudo apt-get update
sudo apt-get install perl libdata-validate-ip-perl libio-socket-ssl-perl git-core
git clone https://github.com/ddclient/ddclient.git
sudo cp -f ddclient/ddclient /usr/sbin/
sudo chmod 700 /usr/sbin/ddclient
sudo mkdir /var/cache/ddclient/
sudo touch /var/cache/ddclient/ddclient.cache
sudo mkdir /etc/ddclient/


Now, for example my website is google.com (Zone) and my cloudflare's registered E-mail address is rehan@gmail.com and i want to change IP address of google.com and www.google.com from that Zone , this will be the config file

Code:
sudo nano /etc/ddclient/ddclient.conf
Code:
use=web, web=checkip.dyndns.org/, web-skip='IP Address'
daemon=600
syslog=yes
ssl=yes
protocol=cloudflare,
zone=google.com,
login=rehan@gmail.com,
password='Global API Key'
google.com, www.google.com

Now, check if everything is working perfectly by running
Code:
sudo ddclient -daemon=0 -debug -verbose -noquiet
If it shows Success and that it was able to change the IP address of the domain/s then continue to run this task at particular time interval, in my case it's 10 minutes
Code:
crontab -e
type 1 and press enter if promoted, then paste this at the end of file (every 10 minute)
Code:
*/10 * * * * /usr/sbin/ddclient -daemon=0
To run it every minute code would be
Code:
* * * * * /usr/sbin/ddclient -daemon=0
 
Nice guide. It is better to create an API token with Zone - DNS - edit, read permissions, Zone resources "Include - All zones" and use it instead of Global API key.
 

Top