Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2018 19:25
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple dynamic DNS update script for a domain in DirectAdmin
# Script for automatically updating the DNS records using the DirectAdmin API.
# Requires you to have curl, dig and json installed.
# By Daniël van de Giessen, 2018-09-10
# Configuration
# Get the currently configured IP address from the authoritive nameserver
CONFIGURED_IP="$(dig +short "${DOMAINNAME}" A @$(dig +short "${DOMAINNAME}" NS | head -n1))"
# Get current external IP address of this machine
CURRENT_IP="$(dig +short"
# Check if the IP needs to be updated
if [[ "${CONFIGURED_IP}" != "${CURRENT_IP}" ]] ; then
# Change the IP through the DA API
# Note: Used --insecure because our DA instance doesn't return the complete intermediate certificate.
# If yours does, it is probably a good idea to remove the --insecure flag
# Browsers deal with this fine since they have the intermediate in their store. curl does not.
RESULT="$(curl -sS --insecure -u "${DA_USERNAME}:${DA_PASSWORD}" "${DA_URL}/CMD_API_DNS_CONTROL?domain=${DOMAINNAME}&action=edit&arecs0=name%3D${DOMAINNAME}.%26value%3D${CONFIGURED_IP}&type=A&name=${DOMAINNAME}.&value=${CURRENT_IP}&json=yes")"
if [[ "$(echo "${RESULT}" | json success)" == "record added" ]] ; then
echo "Updated IP address for ${DOMAINNAME} on DirectAdmin from ${CONFIGURED_IP} to ${CURRENT_IP}! :)"
echo "Failed to update IP address for ${DOMAINNAME} on DirectAdmin from ${CONFIGURED_IP} to ${CURRENT_IP}! :(" >&2
echo "${RESULT}" >&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment