search

"Installing" DuckDNS on the GoFlex Home

To access your GoFlex Home over the internet I recommend DuckDNS. It is very easy to set up your own subdomain and it is free, though you can donate if you want to help to keep this great service operating. Updating your IP address is very simple through their website and they even provide very helpful instructions for setting up a Linux Cron job to automatically update your IP address. Unfortunately their instructions are aimed at a full-blown linux OS and need a bit of tweaking for the GoFlex Home.

Background

I created my post about Seagateshare stopped working now what? a few months ago and set up my own subdomain with duckdns at that time.  My IP address doesn't change for months at a time, until I reboot my router and since I knew I was going to be reflashing my firmware, I didn't bother with setting up a cron job to automatically update my IP address.

If the worst happened and my router reset unexpectedly then I can easily update it manually on the duckdns.org website. Now that I have finished reflashing I thought I would set up a more permanent solution and that's when I noticed some issues.
I am surprised that no-one has posted any comments on my Seagateshare stopped working blog but maybe there are fewer people interested in remote access than I thought.


Issues

The main problem I came across is that the goflex home doesn't have a domain name server so it doesn't know how to handle https://www.duckdns.org in the curl request. Normally /sbin/dhclient-script sets the resolv.conf with the IP address of the router, to piggy-back on the router's domain name server settings. For some reason, my GoFlex Home wasn't setting that and resolv.conf was empty. 
The simple fix of adding a nameserver to the resolv.conf file works but as soon as the service restarts resolv.conf is deleted and none of the fixes I tried survive a reboot, which is when you need it the most. 
I can see in /etc/sysconfig/network-scripts/ exactly where the resolv.conf file is getting replaced but I don't want to poke around in those scripts and more importantly I don't want to encourage you to poke around in those scripts because if anything messes up then you will kill the goflex home ethernet connection and that means you will need to reflash the firmware to restore connectivity.

For a while, the solution was to use the fully resolved IP address instead of the domain name in the request. Or in other words, use https://44.230.159.203/update? instead of https://www.duckdns.org/update?
That's not ideal since IP addresses are prone to change. Fortunately the dhclient-script started working again, but I still don't know what the problem was or what fixed it. 

The second issue is less important, but the default location for the output file in duckdns instructions  ~/duckdns/duck.log creates a duck.log file  in the duckdns folder of the current user's home folder and I prefer to save the output to the Public folder so that regardless of which user runs the task or who you log in as, the file is easily accessible.

duckDNS Linux Cron instructions


As always; first login with SSH and become root user
You can ignore the duckdns.org Linux Cron instructions to check for cron and curl as the goflex home has both cron and curl
And instead of creating a duckdns folder in the current user's home folder and creating a bash script file there we're going to create the script in the existing /usr/bin folder, so ignore the mkdir duckdns, cd duckdns, vi duck.sh steps and instead do the following  (commands that you need to enter are in blue).

vi /usr/bin/duck.sh

enter i to go to INSERT mode, then type or copy/paste the following text, all on a single line and replacing yoursubdomain with your duckdns subdomain and yourtoken with the token provided to you by duckdns.org.

echo url="https://duckdns.org/update?domains=yoursubdomain&token=yourtoken&ip=" | curl -s -k -o /home/0common/duck.log -K -

If you mess up Esc :q! will get you out of vi without saving  and Esc ZZ will save the changes and exit vi. 

Next make the file executable with

chmod 700 /usr/bin/duck.sh

Test the script works with

/usr/bin/duck.sh

If the script has no errors then you should just see the prompt returned. 

If the duck.log file was created but it shows KO instead of OK then check that you entered yoursubdomain and yourtoken correctly.

If it is all working fine then we are ready to set up the cron task.

vi /etc/crontab

type or copy/paste the following     */5 * * * * root /usr/bin/duck.sh >/dev/null 2>&1

That will set the task to run every 5 minutes as root user. 
Esc ZZ to save and exit vi then Reload and Restart the cron service;

/sbin/service crond reload
/sbin/service crond restart

and then monitor the Public folder to check  if the file is being created at the chosen interval

Once everything is working OK then you probably don't even need the output file and writing the log file to the hard disk every five minutes will never give your drive a chance to spin down. 
So I wrote a very simple script which checks the time and only outputs to a file if the time is between 03:00am and 03:59am. The rest of the time it discards the output, but still notifies duckdns.org of your current IP address.

Edit the duck.sh file created previously

vi /usr/bin/duck.sh

enter i to go to INSERT mode, then insert the text below at the start of the file, before the echo url="… line

#!/bin/bash
time=`date +%H`;
output=/dev/null
if [ $time -eq "03" ]
then
output=/home/0common/duckdns.log
fi


edit the echo url=..."  line replacing -o /home/0common/duck.log with -o $output

Esc ZZ to save the changes and exit vi. Now when you run the script with

/usr/bin/duck.sh

You should again see no output and no file created (unless you’re running this at 3am).
If you get errors then check the line starting with time= that you have entered backticks  ` rather than apostrophes and make sure to leave a space each side of each of the square brackets  [  ] .