Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
DigitalOcean dynamic DNS updater script for your subdomain
# Created by // Loranth Moroz // v.0.5
# Required tools to run this script as is: curl ( & jq (
# This only works for Digitalocean - 10$ credit referral link:
# Edit token, domain, subdomain to fit your needs
# Substitute with your own ip-checker e.g.
# This is to be used with crontab -> example entry to run it every 3hours:
# 0 */3 * * * sh /path/to/script/
# Don't forget to make it executable: chmod +x /path/to/script/
token="DO-Developer API_KEY"
domain="Your domain hosted at DO-nameservers"
subdomain="PREPARED subdomain via DO-Interface"
ip=$(curl --silent
record_id=$(curl --silent --request GET --header "Content-Type: application/json" --header "Authorization: Bearer $token" "$domain/records" | jq ".[] | . [] | select(.name==\"${subdomain}\")" 2>/dev/null | grep "id" | sed --regexp-extended "s/[^0-9]//g")
curl --silent -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d '{"data":"'$ip'"}' "$domain/records/$record_id" > /dev/null;
echo -e "\n==DNS updated with IP: $ip=="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.