What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Google Domains DDNS Script

marcusb

Occasional Visitor
Hello all,

I tried in vain to get ddclient or inadyn installed and working to update my Google Domains DDNS but I kept hitting a dead end with weird errors. I decided to write a script (my first!) instead. I admit I copied some things from other people .. even some people on this forum, to get this done. The scripts I had seen did not do a check to see if the IP had changed, so as to not send excessive updates I added a check.

At first I was going to use a DHCPC-EVENT script but for some reason it was executing twice at boot. I decided to schedule it in crontab every hour (@hourly ./gdns) instead, as that should sufficient for my needs. I just named it gdns and placed in the /jffs/scripts directory.

I still use dnsomatic and changeip.com to maintain a second DDNS.. just in case, but I think this will work well for updating Google Domains.

For info on using Google Domains DDNS check here: https://support.google.com/domains/answer/6147083?hl=en


I apologize in advance for the script formatting.. I have very little idea what I'm doing as this is all new to me.

Code:
#!/bin/sh

MyGDomain=yourdomain.com
Username=user generated by Google
Password=pw generated by Google
CurrWANIP=$(nvram get wan0_ipaddr)

if grep -q $CurrWANIP "/jffs/scripts/gdnsip.txt";
	then
        	logger "Google Domains DDNS: WAN IP unchanged, no update necessary"
	else 
		echo $CurrWANIP > /jffs/scripts/gdnsip.txt
        	logger "Google Domains DDNS: Update in 60 seconds"
        	sleep 60s
        	curl -s https://$username:$password@domains.google.com/nic/update?hostname=$MyGDomain&myip=$CurrWANIP
        	logger "Google Domains DDNS: WAN IP update sent"
fi

Edit: I'm not sure if curl is installed by default? Obviously if it isn't I did install it..

Edit 2: Ok, didn't realize crontab is lost with a reboot. I added "/usr/sbin/cru a GDNS "0 * * * * /jffs/scripts/gdns" to services-start script
 
Last edited:
378.50 will include support for custom DDNS services, through a ddns-start script that fully integrates with the rest of the firmware.
 
Ok. I saw other posts where you had said you weren't going to implement any custom DDNS stuff. How will ddns-start work?

Also, I rewrote the script slightly to use dig (requires bind installed) to find the DNS of the domain and use that as a comparison instead of writing the last sent one to a file. This way if an update fails for some reason midway through the script (router reboots during the sleep period for example) it will update the next time. I can post the new one if anyone is interested.
 
Ok. I saw other posts where you had said you weren't going to implement any custom DDNS stuff. How will ddns-start work?

Also, I rewrote the script slightly to use dig (requires bind installed) to find the DNS of the domain and use that as a comparison instead of writing the last sent one to a file. This way if an update fails for some reason midway through the script (router reboots during the sleep period for example) it will update the next time. I can post the new one if anyone is interested.

Instead of implementing it at the webui and ez-ipupdate level (which would be a pain to maintain), I am implementing as a user script similar to the other scripts I implemented.

Basically, the webui will have a "Custom" DDNS entry in the list of supported providers. After selecting that, you will need to create a ddns-start script which will take care of updating your IP with your provider, and running a command to tell the firmware if the update was a success or not. Here is a very basic example for afraid.org:

Code:
#!/bin/sh

wget -q http://freedns.afraid.org/dynamic/update.php?your-privatekey goes-here -O - >/dev/null
if [ $? -eq 0 ]; then
    /sbin/ddns_custom_updated 1
else
    /sbin/ddns_custom_updated 0
fi

Also, the firmware also contains Curl, which is a more complete alternative to wget, and supports HTTPS. So, a user script would also be able to update a provider that requires SSL.

Finally, since it's a script, it means you can also make it run any other Linux program. So if your provider only works with inadyn, then you could compile and copy inadyn to your JFFS partition, have the script run inadyn to do an update, and afterward you notify the rest of the firmware with ddns_custom_updated to let it know if it succeeded or not.

Not as easy as a web interface, but far, far more flexible - it could be used to update any type of service. And I won't have to devote time in trying to support everyone's favorite service - I'd expect users to fill the Wiki with their own scripts, to use as an example for anyone else with those same services.
 
Ok. I saw other posts where you had said you weren't going to implement any custom DDNS stuff. How will ddns-start work?

Also, I rewrote the script slightly to use dig (requires bind installed) to find the DNS of the domain and use that as a comparison instead of writing the last sent one to a file. This way if an update fails for some reason midway through the script (router reboots during the sleep period for example) it will update the next time. I can post the new one if anyone is interested.

I would appreciate if you share your script.
 
I would appreciate if you share your script.

Code:
#!/bin/sh

MyGDomain=yourdomain.com
Username=user
Password=pass

CurrWANIP=$(nvram get wan0_ipaddr)
dig $MyGDomain +short > /jffs/scripts/gdnsip.txt

if grep -q $CurrWANIP "/jffs/scripts/gdnsip.txt";
then
        logger "Google Domains DDNS: WAN IP unchanged, no update necessary"
else
        logger "Google Domains DDNS: Update in 60 seconds"
        sleep 60s
        curl -s https://$Username:$Password@domains.google.com/nic/update?hostname=$MyGDomain&myip=$CurrWANIP
        logger "Google Domains DDNS: WAN IP update sent"
fi
 
Tank you marcusb for sharing your script.
I have modified script to use ca-bundle.crt from here and only after that I was able to run script without issues.
Without that I had this error message: "curl: (60) SSL certificate problem: unable to get local issuer certificate"


Code:
#!/bin/sh

MyGDomain="yourdomain.com"
username="username"
password="password"
gdnsip="/jffs/scripts/gdnsip.txt"
ca_cert="/jffs/scripts/ca-bundle.crt"
CurrWANIP=$(nvram get wan0_ipaddr)

dig ${MyGDomain} +short > ${gdnsip}
if grep -q ${CurrWANIP} "${gdnsip}"; then
  logger "Google Domains DDNS: WAN IP[${CurrWANIP}] unchanged, no update necessary."
else
  echo ${CurrWANIP} > ${gdnsip}
  logger "Google Domains DDNS: Update in 60 seconds. New WAN IP[${CurrWANIP}]"
  sleep 60s
  ip_update=$(curl -s --cacert ${ca_cert} https://${username}:${password}@domains.google.com/nic/update?hostname=${MyGDomain}&myip=${CurrWANIP})
  if [ "${ip_update}" == "good ${CurrWANIP}" ]; then
    logger "Google Domains DDNS: WAN IP[${CurrWANIP}] update sent successfully"
  else
    logger "Google Domains DDNS: WAN IP[${CurrWANIP}] update failed"
  fi
fi
 
Tank you marcusb for sharing your script.
I have modified script to use ca-bundle.crt from here and only after that I was able to run script without issues.
Without that I had this error message: "curl: (60) SSL certificate problem: unable to get local issuer certificate"


That's odd. I retested and reconfirmed that curl works in my original script.. not sure why you had to change anything but I'm glad you figured out something that works for you.

Edit:

Ok, I incorporated some of your ideas and changed some things. I also got rid of the need for the txt file.

Code:
#!/bin/sh

MyGDomain=
Username=
Password=

CurrWANIP=$(nvram get wan0_ipaddr)
GDNSIP=$(dig $MyGDomain +short)

if [ "$CurrWANIP" == "$GDNSIP" ]; then
        logger "Google Domains DDNS: WAN IP ($CurrWANIP) unchanged, no update necessary"
else
        logger "Google Domains DDNS: Update in 30 seconds"
        sleep 30s
        ipupdate=$(curl -s https://$Username:$Password@domains.google.com/nic/update?hostname=$MyGDomain&myip=$CurrWANIP)
        if [ "$ipupdate" == "good $CurrWANIP" ]; then
         logger "Google Domains DDNS: DNS updated to $CurrWANIP from $GDNSIP"
        else
         logger "Google Domains DDNS: Update error"
	 logger "Google Domains DDNS: $ipupdate"
        fi
fi
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Back
Top