Skip to content

Instantly share code, notes, and snippets.

@droM4X
Created October 4, 2021 19:59
Show Gist options
  • Save droM4X/8028d597d4508cc619f3415663f93448 to your computer and use it in GitHub Desktop.
Save droM4X/8028d597d4508cc619f3415663f93448 to your computer and use it in GitHub Desktop.
Cloudflare dyndns script
#!/bin/sh
DYN_HOST='';
CF_BEARER_TOKEN='';
CF_ZONE_ID='';
CF_DNS_ID='';
# ---
CURRENT_IP=$(curl -s https://checkip.amazonaws.com);
DNS_IP=$(resolveip -s $DYN_HOST);
if [ CURRENT_IP != DNS_IP ]
then
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records/$CF_DNS_ID" \
-H "Authorization: Bearer $CF_BEARER_TOKEN" \
-H "Content-Type:application/json" \
--data '{"type":"A","name":"'$DYN_HOST'","content":"'$CURRENT_IP'","ttl":300,"proxied":false}'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment