Dynamic DNS using Cloudflare's API.
This repository contains a bash script that updates a Cloudflare DNS record with the public IP of the machine it's running on.
In order to use this script, you need to have a Cloudflare account and a domain with Cloudflare nameservers.
curl
: The script usescurl
to make requests to the Cloudflare API.grep
: The script usesgrep
to parse the response from the Cloudflare API. This is a standard Unix utility and should be available on most systems.awk
: The script usesawk
to parse the response from the Cloudflare API. This is a standard Unix utility and should be available on most systems.
The script takes three positional arguments:
CF_API_TOKEN
: Your Cloudflare API token.CF_ZONE_ID
: The ID of the zone containing the DNS record you want to update (available in the Cloudflare dashboard).DNS_RECORD_NAME
: The name of the DNS A record you want to update as a fully qualified domain name (e.g.record.example.com
). You need to have this record already created in your Cloudflare account.
bash ./cloudflare-update-dns-record.sh $CF_API_TOKEN $CF_ZONE_ID $DNS_RECORD_NAME
It is recommended to make the script executable and add it to your crontab to run it periodically.
First place the script in an appropriate location, for example /usr/local/bin/cloudflare-update-dns-record.sh
.
# Download the script to /usr/local/bin
curl -o /usr/local/bin/cloudflare-update-dns-record.sh https://raw.githubusercontent.com/lobis/cloudflare-ddns/main/cloudflare-update-dns-record.sh
# Make the script executable
chmod +x /usr/local/bin/cloudflare-update-dns-record.sh
Then open your crontab:
crontab -e
Add the following line to run the script every 5 minutes (replace the placeholders with your actual values):
*/5 * * * * /usr/local/bin/cloudflare-update-dns-record.sh $CF_API_TOKEN $CF_ZONE_ID $DNS_RECORD_NAME