How to set up dynamic DNS (DDNS) on WD My Book Live

Posted by gpall on Fri 13 Jan 2012 at 06:15

Western Digital's My Book Live runs on Debian Lenny. It is a pretty nice NAS missing one critical feature for which many people ask on-line: The ability to sit behind a home LAN router and update a dynamic DNS entry as many routers can do.

Of course if your router natively supports DDNS, then you should go this way and set up the DDNS on the router.

The problem is that DynDNS.org has stopped offering free DDNS services, and few other routers support another free DDNS service.

First of all you should gain root access to the device following one of the many online tutorials.

Then, make an account at no-ip.org and set up your DDNS domain, say: mynas.no-ip.org. Example username and password: mymail@mail.com, mypassword.

Then create a text file named "noip" in your NAS share and put inside the following (one line):

*/15 * * * *   root      /root/update_ip.pl

Then create another file in your NAS share named 'update_ip.pl' and put inside the following:

#!/usr/bin/perl

$ip_file = "/tmp/myBookLiveIP";

$ip = `wget -q checkip.dyndns.org -O -`;

if ($ip =~ /(\d+\.\d+\.\d+\.\d+)/){
  $ip = $1;
  if (-e $ip_file){
    open FH,"<$ip_file";
    $old_ip = <FH>;
    close FH;
    $old_ip = $1 if ($old_ip =~ /(\d+\.\d+\.\d+\.\d+)/);
    if ($old_ip ne $ip){
      #print "ip has changed from $old_ip to $ip\n";
      open FH,">$ip_file";
      print FH $ip;
      close FH;
      update_noip($ip);
    }
  }else{
    open FH,">$ip_file";
    print FH $ip;
    close FH;
    update_noip($ip);
  }
}else{
  exit;
}

sub update_noip{
  my $ip = $_[0];
  print `wget -q -O /dev/null --http-user="mymail\@mail.com" --http-password="mypassword"  "http://dynupdate.no-ip.com/nic/update?hostname=mynas.no-ip.org"`;
}

Warning! Don't forget the escape character '/' in the email in the update_noip subroutine and of course don't forget to change the example username/password with your own!

Then, from the ssh root session on the NAS, move the 'noip' file you created from the share (/DataVolume/...) into the directory /etc/cron.d/ and the file 'update_ip.pl' into /root.

That should be all - every 15 minutes, the NAS will update the hostname with the correct IP of your home's LAN, IF it has changed.

If you're not familiar with command scheduling with cron, we've previously documented it.

--Dr. Giorgos Pallas

 

 


Posted by Anonymous (151.16.xx.xx) on Sat 14 Jan 2012 at 14:34
DynDNS bans your account for unnecessary updates.

[ Parent | Reply to this comment ]

Posted by gpall (109.242.xx.xx) on Sat 14 Jan 2012 at 16:17
[ View Weblogs ]
You meant no-ip maybe?
If you meant no-ip, and if you are behind a NAT, how can you know that it is an unnecessary update?

[ Parent | Reply to this comment ]

Posted by Anonymous (138.40.xx.xx) on Mon 16 Jan 2012 at 11:21
Could you include in the cron entry a check to see what the address currently resolves to and compare it to the (potentially different) new value?

That way you would only need to update no-ip when there is an IP change.

[ Parent | Reply to this comment ]

Posted by gpall (155.207.xx.xx) on Mon 16 Jan 2012 at 11:55
[ View Weblogs ]
I don't quite understand your point. Could you show me the technical way to know what my current IP is, so that I can know if it has changed?

[ Parent | Reply to this comment ]

Posted by Anonymous (87.184.xx.xx) on Tue 7 Feb 2012 at 14:01
(Different Anonymous) I'd say you could ping your domain. Might result in false positives sometimes, but still better than getting banned.

[ Parent | Reply to this comment ]

Posted by gpall (79.107.xx.xx) on Mon 16 Jan 2012 at 17:00
[ View Weblogs ]
So, after some people commented that you may get banned for making unnecessary IP updates, I rewrote the how-to including a simple script I made for checking first using an external IP checker, if your IP has changed, so that only then the update takes place.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.220.xx.xx) on Mon 13 Feb 2012 at 10:42
Hi everyone !
I've tried this on my "My book Live" but it seems not working ?!
the files are at the right places, those mentioned in this tuto, i've replaced the email and pass with my own username(not email) and password and the hostname with mine too !
But my no-ip is not updating at all ?!
Any idea ?

[ Parent | Reply to this comment ]

Posted by gpall (155.207.xx.xx) on Mon 13 Feb 2012 at 11:00
[ View Weblogs ]
First of all try to run the wget command as shown in the script, and see from the no-ip web interface if the IP was updated. Try that and post your findings. I hope your password does not have any special characters like '@' etc...

---
No-one cares if you backup. Only if you can restore.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.220.xx.xx) on Mon 13 Feb 2012 at 12:55
Thank's a lot for your answer !
I've run the script and this is the result :
syntax error at /root/update_ip.pl line 11, near "= ;"
Execution of /root/update_ip.pl aborted due to compilation errors.
So, it seems there's an error.
line 11 is : "$old_ip = ;"

[ Parent | Reply to this comment ]

Posted by gpall (155.207.xx.xx) on Mon 13 Feb 2012 at 13:02
[ View Weblogs ]
Many thanks for finding that. Looks like the html ruined my code at that point. I've now corrected the script and the line reads:
$old_ip = <FH>;

---
No-one cares if you backup. Only if you can restore.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.220.xx.xx) on Mon 13 Feb 2012 at 13:12
Many thanks to you for writing it !!
Can i ask you a last question ?
I'm trying to understand the cron.d concept and i had a look at the page on that subject.
Why don't you write just "*/15 * * * * /root/update_ip.pl" in the noip file ?

[ Parent | Reply to this comment ]

Posted by gpall (155.207.xx.xx) on Mon 13 Feb 2012 at 13:52
[ View Weblogs ]
Hmmm, because that was yet another error of mine :-)
I corrected it and hopefully now it works fine!

The idea of the cron.d concept is that you put inside the /etc/cron.d/ directory files which describe scheduled tasks. So, in our case you we want to execute the update_ip.pl script, as root, every 15 minutes.

[ Parent | Reply to this comment ]

Posted by Anonymous (81.220.xx.xx) on Mon 13 Feb 2012 at 13:52
Oups, i meant :
*/15 * * * * root perl /root/update_ip.pl

[ Parent | Reply to this comment ]

Posted by Anonymous (178.128.xx.xx) on Tue 30 Oct 2012 at 22:53
Try changing the permissions on both files

chmod 777 "filename"

[ Parent | Reply to this comment ]

Posted by josefwells (67.52.xx.xx) on Mon 13 Feb 2012 at 17:50
Use inadyn:
http://www.inatech.eu/inadyn/
http://packages.debian.org/lenny/inadyn (also available for stable, testing, etc)

Supports many different ddns providers (afraid.org rules them all).

Update /etc/inadyn.conf for your service/configuration
crontab -e (as root)
@reboot /usr/sbin/inadyn (or your preferred way if starting stuff at boot)

Profit!

[ Parent | Reply to this comment ]

Posted by Anonymous (109.242.xx.xx) on Mon 13 Feb 2012 at 22:03
I knew the relevant packages (e.g. I use noip2), but I selected the way I wrote above in order to make the minimum possible changes to the disk's system. And installing a packet is a little more intrusive...

[ Parent | Reply to this comment ]

Posted by dkg (108.58.xx.xx) on Tue 14 Feb 2012 at 06:09
[ View dkg's Scratchpad | View Weblogs ]
By regularly truncating and overwriting a file in /tmp/ (a world-writable directory) with a predictable filename, you open yourself up to a symlink attack. Any account on your system can now symlink that file to, say, /etc/passwd, and effectively lock you out of your machine on the next cronjob run.

there may be more clever ways to get privilege escalation (not just a denial of service attack) from this as well.

the easy fix: use a file location that is in a directory only writeable by the user running the script.

[ Parent | Reply to this comment ]

Posted by patosilva (168.226.xx.xx) on Fri 2 Mar 2012 at 20:44
I wrote something like that a few year ago to manage zoneedit dns accounts.

http://www.esdebian.org/wiki/uze-update-zoneedit

GPL of course, it worked well for me in several servers.

[ Parent | Reply to this comment ]

Posted by thelighthunter (113.162.xx.xx) on Sun 9 Sep 2012 at 07:26
I have set my DYNDNS in my router. I can access the router via www this way. However, can somebody tell me how I can now access via that DYNDNS my My Book Life connected to the router via ethernet static IP 192.168.1.99 and ports 80 and 443

[ Parent | Reply to this comment ]

Posted by gpall (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Mon 10 Sep 2012 at 07:06
[ View Weblogs ]
Your question is not clear enough. How you want to access it, and from where?

[ Parent | Reply to this comment ]

Posted by thelighthunter (113.162.xx.xx) on Tue 11 Sep 2012 at 02:11
I would like that the MBL is accessible via the internet by any user for any share I define.
Not only via iPhone or iPad but also computer.
Idea is to share selected pictures with some friends and share other selected pictures with other friends.

[ Parent | Reply to this comment ]

Posted by gpall (2001:0xx:0xx:0xxx:0xxx:0xxx:xx) on Tue 11 Sep 2012 at 06:21
[ View Weblogs ]
Sorry, I don't know how/if you can do that.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 472 votes ~ 5 comments )