Skip to content

Instantly share code, notes, and snippets.

@nexus166
Last active April 14, 2020 11:59
Show Gist options
  • Select an option

  • Save nexus166/c0777ee394fd7d70e451c51fe3866684 to your computer and use it in GitHub Desktop.

Select an option

Save nexus166/c0777ee394fd7d70e451c51fe3866684 to your computer and use it in GitHub Desktop.
Cloudflare DNS Zone A/AAAA update
#!/bin/bash -eu
EMAIL="[email protected]";
APIKEY="xyz"; # https://dash.cloudflare.com/<account_id>/profile/api-tokens
ZONE="abc"; # https://dash.cloudflare.com/<account_id>/<zone>
RECORDID=$(curl -fso- -H "Authorization: Bearer ${APIKEY}" -H "Content-Type: application/json" "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records?name=${1}" | jq -crM '.result[].id');
curl -fso- \
-H "Authorization: Bearer ${APIKEY}" \
-H "Content-Type: application/json" \
-X PUT "https://api.cloudflare.com/client/v4/zones/${ZONE}/dns_records/${RECORDID}" \
--data '
{
"id": "'${RECORDID}'",
"name": "'${1}'",
"type": "'${2:-A}'",
"content": "'${3:-$(curl -fso- icanhazip.com)}'"
}' | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment