Skip to content

Ubiquiti EdgeRouter Dynamic DNS Script

The following is an example of a Dynamic DNS (DDNS) update script for Ubiquiti Networks EdgeRouter using GoDaddy as an example.

vi /etc/dhcp/dhclient-exit-hooks.d/GoDaddy

#!/bin/bash
# Save as /etc/dhcp/dhclient-exit-hooks.d/GoDaddy

# I want to update multiple A records
names=( host1 host2 host3 )

# The domain I own and my GoDaddy API Key/Secret
domain="chasewright.com"
key=""
secret=""
headers="Authorization: sso-key $key:$secret"

currentIp=$(curl -s GET "http://ipinfo.io/ip")
request='{"data":"'$currentIp'","ttl":3600}'

for name in "${names[@]}"
do
    result=$(curl -s -X GET -H "$headers" "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
    dnsIp=$(echo $result | grep -oE "b([0-9]{1,3}.){3}[0-9]{1,3}b")
    if [ $dnsIp != $currentIp ];
    then
        curl -i -s -X PUT -H "$headers" -H "Content-Type: application/json" -d $request 
        "https://api.godaddy.com/v1/domains/$domain/records/A/$name"
    fi
done

Now all you have to do is make it executable using chmod:
chmod +x /etc/dhcp/dhclient-exit-hooks.d/GoDaddy

WARNING: Scripts do not persist after an upgrade. You have to re-install them.

Published inTech

One Comment

  1. I do something very similar. You can have the scripts survive upgrades by putting them under the /config directory. I created te following…

    /config/scripts

    and then put the scripts in there. in your instance

    /config/scripts/GoDaddy

    Then I have it run via the task scheduler every 5 minutes or so… I’t only reaches out to GoDaddy if the IP has actually changed. If not, it just exits.

Leave a Reply

Your email address will not be published. Required fields are marked *