Before I go any further, I’d like to warn you that this post about using FreeBSD to assign an address to a Western Digital MyBook drive is unnecessarily verbose. See, I could have just as easily said "this post is long".

Writing about theoretical uses for software is one thing, but figuring out how to apply software to a problem practically, and actually getting it work, is one of the greatest feelings in the world alongside writing a fantastic piece of software yourself to solve a problem. It makes me feel useful and gives me a rush quite unlike anything else.

And he’s available ladies! Unbelievable though it may seem! Come on! He also makes a mean Earl Grey latte. Any bidders? Anyone?

Case in point, my sister and I had a problem in our new house in Adelaide. Before I left Singapore, I bought a gigabit ethernet Western Digital MyBook 1GB World Edition NAS drive and loaded it up with all our media: movies, shows, music, podcasts, BSD disk images, ebooks. By using a simple network drive, we spared ourselves having to bring a separate computer down with us.

Our makeshift home network consists of each of our laptops and the aformentioned network drive which are all connected through short Cat-6 ethernet cables to a 5 port gigabit Ethernet switch. To compensate for the lack of a router, I assigned my sister’s MacBook and my MacBook Pro static IP addresses and I knew the network drive could also be assigned one. Very cool.

Our very fancy new home network
Our very fancy new home network.

Now here’s the kicker: for some reason in their infinite wisdom Western Digital decided not to ship the MyBook with a default IP address. This means it requires a DHCP server (Wikipedia link) to initally provide it with an address. I realised that without a router with a built in DHCP server, this network drive wouldn’t get an address, and therefore there’d be no way for me to log into it to assign it a static IP! Catch 22, chicken and the egg, a Bruce Schneier fact, call it what you will.

So within a few minutes I had configured a home network with two laptops and an inaccessible, address-less network drive. It seemed not having a router with a built in DHCP server would make this setup impossible. A quick Perl script determined that indeed only the two laptops were in our subdomain range:

#!/usr/bin/env perl -w

for ($i = 1; $i < 255; $i++) {
  system "ping -a -c 2 192.168.1.$i";
}

print "Western Digital engineers love DHCP it seemsn"

At this point I had to make a tough decision. To access our media network drive I could either be patient and wait a week until we got our new broadband modem with a built in router, or I could be impatient. Grilled cheese sandwich. Grilled cheese sandwich?

I decided to do the latter and give it what it wanted: a DHCP server! In place of a router, I would configure a one-time use FreeBSD virtual machine with a software DHCP server which would assign the address to the network drive, so I could log into it remotely and assign it a static IP.

My FreeBSD virtual machine showing the DHCP server coming online
My FreeBSD virtual machine showing the DHCP server coming online

After setting up a generic VMware Fusion virtual machine on my MacBook Pro, I mounted a FreeBSD 7.0-RELEASE ISO I had on already had on my hard drive and installed it with all the default options. I skipped configuring everything in the system installer except than the network card. I declined to use DHCP when it asked, and assigned it a static IP.

After rebooting the VM, I logged in as root and installed the isc-dhcp3-server package from ports.

I didn’t bother adding anything fancy to the /usr/local/etc/dhcpd.conf other than defining the pool of addresses and required options:

option domain-name "chuckpeddle";
option subnet-mask 255.255.255.0;

default-lease-time 3600;
max-lease-time 86400;
ddns-update-style none;

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.120 192.168.1.129;
}

Next, to check what addresses our makeshift DHCP server has assigned, I created the default dhcpd.leases file:

# touch /var/db/dhcpd.leases

Finally, I enabled the dhcpd daemon in /etc/rc.conf and told it what card I wanted FreeBSD to listen for DHCP requests on. On VMware Fusion 1.1.3, the network card in FreeBSD is le0, but you can always check to make sure by using ifconfig -a

dhcpd_enable="YES"
dhcpd_ifaces="le0"

The moment of truth had arrived! I turned off my Western Digital MyBook NAS drive, rebooted the FreeBSD virtual machine, then turned the network drive back on again. After a minute of waiting, sure enough the /var/db/dhcpd.leases file reported that it had assigned an address…

lease 192.168.1.129 {
  starts 6 2008/08/02 14:37:12;
  ends 6 2008/08/02 15:37:12;
  binding state active;
  next binding state free;
  […]
  client-hostname "RubenerdNAS";
}

… and automagically the Finder on my MacBook Pro reported it had found a new samba share (with it’s irreverent sense of humour)! My network drive had been resurrected from the dead!

My Western Digital MyBook in the Finder
My Western Digital MyBook in the Finder

Finally, after all of that I was able to go to my web browser and log into the damned network drive’s configuration page and change the IP address to a static one.

I still can’t help but wonder why Western Digital decided not to include a default address.

Western Digital NAS config screen, and the FreeBSD DHCP virtual machine
Western Digital NAS config screen, and the FreeBSD DHCP virtual machine

And now if you’d excuse me, I’m off to watch an episode of Cranky Geeks. From my network drive. PHEW!