Cloudflare DDNS is an automated solution for those who:
Cloudflare DDNS automatically updates DNS records on the Cloudflare platform when the IP address of the machine it is running on has changed. It is a Python script that can be automated with the use of cron jobs and can either retrieve the configuration hardcoded from within the script or from an external JSON file specified on the commandline. The script leverages multiple APIs to determine the public IP address of the machine it is running on. If the IP address has changed, the corresponding domain names hosted on Cloudflare are updated. The script also randomly updates DNS (on average every 4 hours) for redundancy in case there was a network error running it previously.
Prerequisites:
Configure the script:
You will need to add your domain names and their corresponding DNS records, API key, and email address.
This can be done by either hardcoding the values into the Python script or by editing the zones.json file
which is in the same directory as Cloudflare_DDNS.py.
Running the script:
Open a terminal or command prompt and navigate to the location where the Python program is stored.
If using the internal configuration, type in the command:
python3 Cloudflare_DDNS.pyIf using the external file zones.json for the configuration type in the command:
python3 Cloudflare_DDNS.py zones.jsonThe script will then determine the IP address of the machine it is running on by using one of multiple APIs. If the IP address has changed, the script will update the DNS records for all the domain names in the config with the new IP address.
Scheduling the script to run periodically:
It is recommended to run the script every 8 minutes to ensure that the DNS records are always up-to-date. If it is ran too often, the IP address APIs could start to block you preventing this script from running properly.
You can use cron to schedule the script to run automatically:
Edit your crontab with vim by runing the command crontab -e
and add the following line at the end of the file after changing /loc/to/file/ to be the actual location of directory:
*/8 * * * * /usr/bin/python3 /loc/to/file/cloudflare_ddns.py /loc/to/file/zones.json >> /loc/to/file/cloudflare_ddns.log
Starting.... cloudflareddns.com DNS for www.cloudflareddns.com updated to 12.34.56.78 ----------------------------------------- cloudflareddns.com DNS for cloudflareddns.com updated to 12.34.56.78 ----------------------------------------- www.brentrussell.com DNS for www.brentrussell.com updated to 12.34.56.78 ----------------------------------------- brentrussell.com DNS for brentrussell.com updated to 12.34.56.78 ----------------------------------------- ################# RESULTS ################# 4 record(s) updated and 0 error(s)
Download from Github
Visit brentrussell.com