Skip to content

Instantly share code, notes, and snippets.

@ImpulseTheFox
Forked from lg/update-cloudflare-v4-ip.sh
Last active October 24, 2019 23:39
Show Gist options
  • Save ImpulseTheFox/20ebdae07049d3f42467fb21ae445f05 to your computer and use it in GitHub Desktop.
Save ImpulseTheFox/20ebdae07049d3f42467fb21ae445f05 to your computer and use it in GitHub Desktop.
CloudFlare v4 API DNS entry updater
*/5 * * * * /usr/local/bin/foxdd 1>/dev/null 2>&1
#!/bin/sh
# CloudFlare v4 API DNS entry updater
EMAIL="" # CloudFlare email
TOKEN="" # global API key
ZONE_ID="" # 32 digits and letters
DNS_RECORD_ID="" # 32 digits and letters
DNS_RECORD_HOST="" # domain (example: domain.tld or my.domain.tld)
DNS_RECORD_TYPE="A" # example: A, AAAA, TXT...
DNS_RECORD_TTL=1 # 1 is automatic
NEW_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
PROXIED="false" # true or false (orange cloud)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$DNS_RECORD_ID" \
-H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $TOKEN" -H "Content-Type: application/json" \
--data "{\"type\":\"$DNS_RECORD_TYPE\",\"name\":\"$DNS_RECORD_HOST\",\"content\":\"$NEW_IP\",\"ttl\":$DNS_RECORD_TTL,\"proxied\":$PROXIED}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment