Skip to content

Instantly share code, notes, and snippets.

@dtsdwarak
Last active October 5, 2022 03:11
Show Gist options
  • Save dtsdwarak/19abfd5d1ae18c4cd929d082b9d207fc to your computer and use it in GitHub Desktop.
Save dtsdwarak/19abfd5d1ae18c4cd929d082b9d207fc to your computer and use it in GitHub Desktop.
CLOUDFLARE DNS UPDATE SCRIPT
######################################################################################
# CLOUDFLARE DNS UPDATE SCRIPT
# Documentation : https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
# Author: @dtsdwarak
######################################################################################
#! /bin/bash
zone_identifier=kqgsnbdYFSxFEqpzl7vV
dns_record_identifier=yMlGtxPWAsVIRv2kKbRe
[email protected]
cloudflare_auth_key=2ka8HXFpAE0gU05f3s55
hourstamp=$(date +"%F-%H")
past_ip=$(cat /home/your-user/scripts/ip.log)
publicip=$(curl https://api.ipify.org 2>/dev/null)
if [ $past_ip = $publicip ]; then
printf "\n$(date) : IP Address of drive.dwarak.in not changed.\n" >> /var/log/cloudflare/dns-drive-dwarak-in-update/$hourstamp.log
exit 1
fi
echo $publicip>/home/your-user/scripts/ip.log
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns_record_identifier" \
-H "X-Auth-Email: $cloudflare_email" \
-H "X-Auth-Key: $cloudflare_auth_key" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"drive","content":'\"$publicip\"',"ttl":120,"proxied":false}' > /dev/null
printf "\n$(date) : Changed IP address of drive.dwarak.in to $publicip \n" >> /var/log/cloudflare/dns-drive-dwarak-in-update/$hourstamp.log
@andycarver101
Copy link

Log file updates but zone does not. What have I done wrong?

@dtsdwarak
Copy link
Author

Log file updates but zone does not. What have I done wrong?

I see the API hasn't changed. Can you please check and see if you are able to make a PUT request to the endpoint with the values hardcoded?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment