Script for automatic duckdns updates

Posting this, hoping it helps someone someday!

I wanted to be able to access a relative's network periodically to help with network maintenance. I had provided them an OpenWRT router all set up, ready to go - with a few additional mods. I set up a subdomain for free, and made a quick script to keep it updated. I also added my ssh key and disabled password access. Moments after they plugged it in, I could access it!

Here's the simple script I made:

Create /etc/config/ (replace DUCKDNS info in the curl command)


#let the system boot up before attempting to check the ip address...
sleep 30

#install curl dependency (in case of import after firmware update)
opkg update 2>/dev/null 1>&2
opkg install curl 2>/dev/null 1>&2


while :
#capture interface addresses
  IP=$(ip addr | grep 'inet')  

  if [ "$IP" != "$OLDIP" ]; then
    #change detected! Update
    curl "<DUCKDNS SUBDOMAIN>&token=<DUCKDNS TOKEN>&ip=" 2>/dev/null 1>&2

#Repeat the check after 2 minutes
sleep 120

Then add this to /etc/rc.local:

#Script for updating subdomain
/etc/config/ &

This is dirt simple and has been working for months. I am ignoring the OK/KO return from curl, because frankly, if its not 'OK', I can't do anything remotely anyhow...

The beauty of this method is that it never has to reach out to the internet unless a change has occurred.

duckdns is supported by ddns.