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

# 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
headers="Authorization: sso-key $key:$secret"

currentIp=$(curl -s GET "http://ipinfo.io/ip")

for name in "${names[@]}"
    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 ];
        curl -i -s -X PUT -H "$headers" -H "Content-Type: application/json" -d $request 

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.