Skip to content

Instantly share code, notes, and snippets.

@tuupola
Created September 10, 2023 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuupola/bd35132d1ce1b4833abfb4f9d688e089 to your computer and use it in GitHub Desktop.
Save tuupola/bd35132d1ce1b4833abfb4f9d688e089 to your computer and use it in GitHub Desktop.
Update GANDI dynamic DNS
#!/usr/bin/bash
API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
DOMAIN="example.com"
SUBDOMAIN="dynamic"
CURRENT_IP=$(curl --silent --header "Authorization: Bearer $API_KEY" https://dns.api.gandi.net/api/v5/domains/$DOMAIN/records/$SUBDOMAIN/A | jq -r ".rrset_values[0]")
EXTERNAL_IP=$(curl --silent ifconfig.io)
JSON=$(cat <<EOF
{
"items":[
{"rrset_type":"A", "rrset_values":["${EXTERNAL_IP}"], "rrset_ttl": 900}
]
}
EOF
)
if [ $CURRENT_IP == $EXTERNAL_IP ]; then
echo "Nothing to do."
else
curl https://api.gandi.net/v5/livedns/domains/$DOMAIN/records/$SUBDOMAIN \
--request PUT \
--header "Authorization: Bearer $API_KEY" \
--header "Content-type: application/json" \
--data "$JSON" \
--silent
echo "";
echo "Updated $SUBDOMAIN.$DOMAIN A record to $EXTERNAL_IP."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment