#!/bin/bashZONE="johnburch.co.uk"RECORD="spain"FQDN="${RECORD}.${ZONE}."NS="92.27.6.45" # replace with your actual UK server IP or hostnameKEY="/home/john/.bind-ddns.key"TTL=300IP_FILE="/var/tmp/current_ip.txt"CURRENT_IP=$(curl -s https://api.ipify.org)# Skip update if IP hasn't changedif [ -f "$IP_FILE" ] && grep -q "$CURRENT_IP" "$IP_FILE"; then echo "$(date) - IP unchanged: $CURRENT_IP" exit 0fiecho "$(date) - IP changed to $CURRENT_IP, updating..."# Send dynamic DNS updatensupdate -k $KEY <<EOFserver $NSzone $ZONEupdate delete $FQDN Aupdate add $FQDN $TTL A $CURRENT_IPsendEOF# Save the new IPecho "$CURRENT_IP" > "$IP_FILE"Save this script in
/usr/local/bin/update-ddns.shThen setup a CRON job
*/5 * * * * /usr/local/bin/update-ddns.sh >> /var/log/ddns.log 2>&1