Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonSwindle/b9c8d6a9cfad4bbc06e430c5daf6d55f to your computer and use it in GitHub Desktop.
Save JasonSwindle/b9c8d6a9cfad4bbc06e430c5daf6d55f to your computer and use it in GitHub Desktop.
Batch: Cloudflare APIv4 dynamic update A-record script. Created for a Synology NAS hosted Wordpress website.
# set shell variables with your contents
email="email@example.com"
authKey=""
zoneid=""
dnsrecord=""
domain="example.com"
# Collect current IP
current_ip=$(curl --silent --show-error --fail ipecho.net/plain) || exit
# ...and submit
curl --silent --show-error --fail -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records/$dnsrecord" \
-H "X-Auth-Email: $email" \
-H "X-Auth-Key: $authKey" \
-H "Content-Type: application/json" \
--data @- <<END;
{
"id": "$zoneid",
"type": "A",
"name": "$domain",
"content": "$current_ip",
"zone_name": "$domain"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment