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.
Be First to Comment