Last active
July 14, 2019 12:45
-
-
Save voxxit/95282598a5c4277f368b to your computer and use it in GitHub Desktop.
Dynamic DNS script for DigitalOcean. For example: to use with OpenWRT routers, install bash (opkg install bash) then place this script in /etc/hotplug.d/iface/
This file contains 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 characters
#!/usr/bin/env bash | |
set -x | |
# Domain you wish to update | |
DOMAIN="example.com" | |
# Get the v4/v6 addresses from icanhazip.com [pretty reliable!] | |
IPV4_ADDR=`wget -4 -q -O - icanhazip.com` | |
IPV6_ADDR=`wget -6 -q -O - icanhazip.com` | |
# Get your v2 API token from here: https://cloud.digitalocean.com/settings/tokens/new | |
TOKEN="..." | |
# Add the record IDs you wish to update here | |
V4_RECORDS=(123 ...) | |
V6_RECORDS=(678 ...) | |
for RECORD in $V4_RECORDS | |
do | |
wget \ | |
-O - \ | |
--quiet \ | |
--no-check-certificate \ | |
--method="PUT" \ | |
--header="Content-Type: application/json" \ | |
--header="Authorization: Bearer $TOKEN" \ | |
--body-data="{\"data\":\"$IPV4_ADDR\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD" | |
done | |
for RECORD in $V6_RECORDS | |
do | |
wget \ | |
-O - \ | |
--quiet \ | |
--no-check-certificate \ | |
--method="PUT" \ | |
--header="Content-Type: application/json" \ | |
--header="Authorization: Bearer $TOKEN" \ | |
--body-data="{\"data\":\"$IPV6_ADDR\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really nice script, it helped me to bootstrap mine 😄
A few suggestions if I may:
Lines 8-9:
-4
and-6
to wget you can query explicitly ipv4.icanhazip.com and ipv6.icanhazip.com respectively.https://
for extra bit of securityLines 14-16:
GET
onhttps://api.digitalocean.com/v2/domains/$DOMAIN_NAME/records
should return them.Lines 23 and 35:
--no-check-certificate
? DigitalOcean returns valid certificate and by skipping the check you're downgrading security of your connection.