Skip to content

Instantly share code, notes, and snippets.

@andreigec
Last active April 11, 2019 01:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreigec/f9455439c912ffc05738975f89517bc4 to your computer and use it in GitHub Desktop.
Save andreigec/f9455439c912ffc05738975f89517bc4 to your computer and use it in GitHub Desktop.
using v4 of the cloudflare api, update an A record to match that of the current IP. Useful to run instead of ddns services
## update a cloudflare dns a record to your current IP address
#get ZONE from cloudflare homepage for your app and use below where you see ZONE
#GET your dns record id to use in place of DNS_RECORD_ID with the following:
#1- get your email and key from cloudflare website (global API key)
#2- do a get call to https://api.cloudflare.com/client/v4/zones/ZONE/dns_records with the headers:
#x-auth-email and x-auth-key fields (your email and key from above)
#3-call will return an array of your dns records with their ID to use below - you will need your email and key again.
IP=$(curl -s https://canihazip.com/s)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/ZONE/dns_records/DNS_RECORD_ID" \
-H "X-Auth-Email: EMAIL" \
-H "X-Auth-Key: APIKEY" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"dns","content":"'$IP'","ttl":120,"proxied":false}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment