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


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2012 gpall - please ask for permission to republish or translate.