The script will allow you to automatically update an existing DNS record (type A or AAAA) in your CloudFlare account.
Do you manage your DNS in CloudFlare but you don’t have a static IP? The solution is CF-DDNS-update.sh
!
It is available as a minimal Docker image too.
\
The script will allow you to automatically update an existing DNS record (type A or AAAA) in your CloudFlare account.
It works using CloudFlare API-v4 (see documentation here).
In order to use the script you will need an API Token. You can simply run the script for a single-run update.
If you want to maintain your DNS record up to date you have to schedule the execution of the script: you can just add a line in your crontab file.\
For further details see the sections below.
These are the steps to follow to generate the API token:
The configuration must be held in a separate file or passed via command options.
This is the mandatory option (with the config file):
-c config_file_path
These are the mandatory options (without the config file):
-s security_token
-r record_name
-z zone_name
These options can be omitted:
-t record_type
(A for IPv4 or AAAA for IPv6 - Default A)-T record_ttl
(in seconds - Default 120)-p boolean
(true if proxied, false otherwise - Default false)-f boolean
(true if you want to force the update even if the IP isn’t changed - Default false)See cf_ddns_config_sample.sh
for an example.
You can set a crontab entry to schedule the execution of the script.
\
For example, this entry will execute the script every 10 minutes:
*/10 * * * * /*path_to_the_script*/CF-DDNS-update.sh -c *config_file_path* >> /dev/null 2>&1
You must add the entry at the end of the cron file. To open the cron file run crontab -e
.
If you want the script to log the updates in a file, you can add a file as output:
*/10 * * * * /*path_to_the_script*/CF-DDNS-update.sh -c *config_file_path* >> /var/log/*log_file.log* 2>&1
where /var/log/*log_file.log*
must be the full path of your file.
The CloudFlare-ddns Docker image supports amd64, arm64, ppc64le and arm/v7 host architectures. The correct image for your system will automatically be downloaded.
You can simply run:
docker run -d \
-e CFTOKEN=*token_api_goes_here* \
-e RECORD_NAME=test.test.com \
-e ZONE_NAME=test.com \
--restart always \
--name cloudflare-ddns \
antoorofino/cloudflare-ddns
If you want to specify all the options, you should run:
docker run -d \
-e CFTOKEN=*token_api_goes_here* \
-e RECORD_NAME=test.test.com \
-e ZONE_NAME=test.com \
-e RECORD_TYPE=A \
-e RECORD_TTL=120 \
-e RECORD_PROXIED="false" \
-e FORCE="false" \
--restart always \
--name cloudflare-ddns \
antoorofino/cloudflare-ddns
You should add --security-opt seccomp:unconfined
paramater to docker run command. See issue.
docker run -d \
--security-opt seccomp:unconfined \
-e CFTOKEN=*token_api_goes_here* \
-e RECORD_NAME=test.test.com \
-e ZONE_NAME=test.com \
--restart always \
--name cloudflare-ddns \
antoorofino/cloudflare-ddns
In order to execute the script you must set the the right execution permissions to the file.\
You can simply run:
chmod +x /*path_to_the_script*/CF-DDNS-update.sh
You’ll need jq
command-line JSON processor.