This script updates the Cloudflare DNS record for a domain to match your current external IP address. It compares the current external IP of your machine with the IP registered in the DNS record and updates Cloudflare if the IPs don't match. The script logs this operation using the system logger.
- Ensure
curl
andjq
are installed on your system. - You'll need your Cloudflare API Token, zone ID, DNS record ID.
-
Install
curl
andjq
:sudo apt update sudo apt install curl jq
-
Cloudflare API Setup:
- Go to your Cloudflare dashboard.
- Create an API Token (must have permission to edit DNS records).
- Retrieve your Zone ID from the overview section
- Select a DNS record and fetch its DNS Record ID (Find it by running the following script)
api_token="API_TOKEN" curl --request GET \ https://api.cloudflare.com/client/v4/zones/1234567890abcdef/dns_records/abcdef1234567890 \ -H "Authorization: Bearer $api_token" | jq -r '.result.content'
-
Edit the Script: Replace the placeholders in the script with your actual data:
domain
zoneid
api_token
dns_record_id
Run this script manually or set it as a cron job for periodic checks and updates. Make sure you have execute permission.
./dns-update.sh
To run this every 5 minutes:
crontab -e
Add the following line:
*/5 * * * * /path/to/your/script/dns-update.sh
The script logs IP changes to the system log. You can check the logs with:
tail -f /var/log/syslog
- Adjust the TTL (Time to Live) in the Cloudflare update request if necessary. The default is set to 600 seconds (10 minutes).
This script is free to use and modify as needed. No warranty is provided.