Forked from Tras2/cloudflare-ddns-update.sh
Last active
January 30, 2024 02:38
Revisions
-
jooosh renamed this gist
Dec 19, 2021 . 1 changed file with 11 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ # A bash script to update a Cloudflare DNS A record with the external IP of the source machine # Used to provide DDNS service for my home # Needs the DNS record pre-creating on Cloudflare @@ -13,42 +11,37 @@ zone=example.com dnsrecord=www.example.com ## Cloudflare authentication details ## keep this private cloudflare_token=<YOUR_CF_TOKEN_HERE> # Get the current external IP address ip=$(curl -s -X GET https://checkip.amazonaws.com) echo "Current IP is $ip" if host $dnsrecord 1.1.1.1 | grep "has address" | grep "$ip"; then echo "$dnsrecord is currently set to $ip; no changes needed" exit fi # if here, the dns record needs updating # get the zone id for the requested zone zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \ -H "Authorization: Bearer $cloudflare_token" \ -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') echo "Zoneid for $zone is $zoneid" # get the dns record id dnsrecordid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records?type=A&name=$dnsrecord" \ -H "Authorization: Bearer $cloudflare_token" \ -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') echo "DNSrecordid for $dnsrecord is $dnsrecordid" # update the record curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records/$dnsrecordid" \ -H "Authorization: Bearer $cloudflare_token" \ -H "Content-Type: application/json" \ --data "{\"type\":\"A\",\"name\":\"$dnsrecord\",\"content\":\"$ip\",\"ttl\":1,\"proxied\":false}" | jq -
Tras2 revised this gist
Jul 17, 2018 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,13 @@ ip=$(curl -s -X GET https://checkip.amazonaws.com) echo "Current IP is $ip" if host $dnsrecord 1.1.1.1 | grep "has address" | grep "$ip"; then echo "$dnsrecord is currently set to $ip; no changes needed" exit fi # if here, the dns record needs updating # get the zone id for the requested zone zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \ -H "X-Auth-Email: $cloudflare_auth_email" \ -
Tras2 created this gist
Jul 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/bin/bash # A bash script to update a Cloudflare DNS A record with the external IP of the source machine # Used to provide DDNS service for my home # Needs the DNS record pre-creating on Cloudflare # Proxy - uncomment and provide details if using a proxy #export https_proxy=http://<proxyuser>:<proxypassword>@<proxyip>:<proxyport> # Cloudflare zone is the zone which holds the record zone=example.com # dnsrecord is the A record which will be updated dnsrecord=www.example.com ## Cloudflare authentication details ## keep these private cloudflare_auth_email=me@cloudflare.com cloudflare_auth_key=1234567890abcdef1234567890abcdef # Get the current external IP address ip=$(curl -s -X GET https://checkip.amazonaws.com) echo "Current IP is $ip" # get the zone id for the requested zone zoneid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone&status=active" \ -H "X-Auth-Email: $cloudflare_auth_email" \ -H "X-Auth-Key: $cloudflare_auth_key" \ -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') echo "Zoneid for $zone is $zoneid" # get the dns record id dnsrecordid=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records?type=A&name=$dnsrecord" \ -H "X-Auth-Email: $cloudflare_auth_email" \ -H "X-Auth-Key: $cloudflare_auth_key" \ -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id') echo "DNSrecordid for $dnsrecord is $dnsrecordid" # update the record curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneid/dns_records/$dnsrecordid" \ -H "X-Auth-Email: $cloudflare_auth_email" \ -H "X-Auth-Key: $cloudflare_auth_key" \ -H "Content-Type: application/json" \ --data "{\"type\":\"A\",\"name\":\"$dnsrecord\",\"content\":\"$ip\",\"ttl\":1,\"proxied\":false}" | jq