-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set shell variables with your contents | |
email="[email protected]" | |
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