Skip to content

Instantly share code, notes, and snippets.

@marshyski
Created March 20, 2022 19:29
Show Gist options
  • Save marshyski/02d027cb87c8e2dd71c03b7083d0aeb0 to your computer and use it in GitHub Desktop.
Save marshyski/02d027cb87c8e2dd71c03b7083d0aeb0 to your computer and use it in GitHub Desktop.
Update Cloudflare DNS Record with Dynamic IP
#!/bin/sh
CF_TOKEN=""
ZONE_ID=""
SITE_ID=""
DNS_RECORD="foobar.com"
PUB_IP=$(dig @1.1.1.1 ch txt whoami.cloudflare +short | cut -d\" -f 2)
curl -XPUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$SITE_ID" \
-H "Authorization: Bearer $CF_TOKEN" -H "Content-Type: application/json" \
-d "{\"type\":\"A\",\"name\":\"$DNS_RECORD\",\"content\":\"$PUB_IP\",\"ttl\":1,\"proxied\":true}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment