From 39577ccc0611c1589f4a77cf7fd95d79322470ef Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 16 Feb 2021 21:18:04 +0100 Subject: [PATCH] cloudflare dyndns tweaks --- bin/cloudflare-dyndns.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/bin/cloudflare-dyndns.sh b/bin/cloudflare-dyndns.sh index 10686cd..15913f1 100755 --- a/bin/cloudflare-dyndns.sh +++ b/bin/cloudflare-dyndns.sh @@ -2,21 +2,34 @@ # Required env vars # CLOUDFLARE_ZONE="xxx" -# CLOUDFLARE_DNS_RECORD_ID="xxx" +# CLOUDFLARE_DNS_RECORD_ID_A="xxx" +# CLOUDFLARE_DNS_RECORD_ID_AAAA="xxx" # CLOUDFLARE_EMAIL="xxx" # CLOUDFLARE_KEY="xxx" # Update Cloudflare DNS record with current detected public IP # https://api.cloudflare.com/#dns-records-for-a-zone-patch-dns-record function updateIp { - IPADDR=$(curl -s checkip.amazonaws.com) - echo $IPADDR - curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID" \ + # IPv4 A record + IPADDRv4=$(dig @resolver4.opendns.com myip.opendns.com +short) + echo "Public IPv4: $IPADDRv4" + + curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_A" \ -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ -H "X-Auth-Key: $CLOUDFLARE_KEY" \ -H "Content-Type: application/json" \ - --data "{\"content\":\"$IPADDR\"}" + --data "{\"content\":\"$IPADDRv4\"}" + + # IPv6 AAAA record + IPADDRv6=$(dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6) + echo "Public IPv6: $IPADDRv6" + + curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_AAAA" \ + -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ + -H "X-Auth-Key: $CLOUDFLARE_KEY" \ + -H "Content-Type: application/json" \ + --data "{\"content\":\"$IPADDRv6\"}" } updateIp \ No newline at end of file