-
Create an API token. Go to Profile > API Tokens and create a token.
-
Use the API to list your zones to deterimine ID of the zone you want to update.
-
Use the API to list your zone records to determine the ID of the record(s) you want to update.
-
Use the following bash script to update these records, filling in your API token, zone id, and record ids:
#!/bin/bash
api_token="YOUR API TOKEN"
zone="YOUR ZONE ID"
records=("YOUR 1st RECORD ID" "YOUR 2nd RECORD ID" "YOUR 3rd RECORD ID")
public_ip=$(curl -s "http://ipecho.net/plain")
echo "Public IP is ${public_ip}"
for record in "${records}"; do
echo "Updating ${zone} -> ${record}"
curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/${zone}/dns_records/${record}" \
-H "Authorization: Bearer ${api_token}" \
-H "Content-Type:application/json" \
--data "{\"content\":\"${public_ip}\"}"
echo ""
done
- Create a systemd timer or cron job to run this script periodically, e.g. every hour.