Linux Geek‎ > ‎

Lan-HD (automating samba shares)

posted Oct 17, 2009 8:13 AM by Bruno Braga   [ updated Oct 24, 2009 12:37 AM ]
I just purchased a NAS Bufallo LS-XHL 1TB, (also called Lan hard drive) to ease the pain of saving all my files inside my laptop (and of course, considering that I have multiple computers at home). It was my first time setting up this, and it is always gratifying to see the advertisement and manuals saying: "for Windows Vista or Mac OS". Well, of course that means nothing as I already know that there aren't many Linux only customers (this reality will change, we already got 1% of the cake! ).

Anyway, just to keep here my experience with it.

Plugging the HD in to my network

Note: Image extracted from manual.

Locating the HD

I figured that it would connect to my network (with offers DHCP) by default. The issue was just to locate it. Thanks to nmap, this is very easy:

nmap 192.168.X.1/24

This command will do a scan/portscan on every IP from segment X (router's default segment, usually 1 or 11) from 1 to 254.

And, bingo! I found my hard-drive (just reminding that nmap gets me much more than just IPs, and I could verify that default settings came with no sharing options, maybe they were expecting a direct USB connection or an installation application that would guide the user). As we don't have any of that on Linux, we do it the hard way...

Starting Nmap 4.76 ( http://nmap.org ) at 2009-10-18 00:59 JST

Interesting ports on 192.168.X.Y:
Not shown: 989 closed ports
PORT      STATE SERVICE
80/tcp    open  http
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
515/tcp   open  printer
873/tcp   open  rsync
3689/tcp  open  rendezvous
8873/tcp  open  unknown
9050/tcp  open  tor-socks
22939/tcp open  unknown


Detecting that the port 80 (HTTP) was opened, I figured that everything could be done with a web interface (only if I have looked th e complete manual online, that does not come with the product itself...)

So I just opened the browser and entered http://192.168.X.Y/ and voila!



I will skip the boring configuration for this (I am sure no one will have problems here).

Opening the HD

Once I properly configured (opened access as FTP, Windows and Mac, restricted to users: admin for read/write with proper password) the HD, I noticed (thru nmap) that now ports 21 and 22 became opened. My first action then was to open from Nautilus GUI, by typing:

ftp://admin@192.168.X.Y/disk1/sharedfolder/

This works fine, but I got (from the manual for Mac connection) that Windows support is interpreted in Unix environment OS's with Samba, so I gave it a try to:

smb://192.168.X.Y/sharedfolder/

It works much better/faster. I will keep this one. Note the difference for connecting with FTP: you need to add the root name of the disk to make it work.

Automating Samba Shares


As I got everything running, I thought that it would be nice to have the HD always available to me, as if it was there (being plugged in to my network, unlikely to be shutdown). So I searched a bit here and here, and everything works great for me now.



But, for personal references, I will leave reported what I did:

# check if you need to install samba dependencies
sudo apt-get -y install smbfs

# create media folder to be mounted (NW-HD-1TB is the name I chose to give to my HD)

sudo mkdir /media/NW-HD-1TB

# create credentials for fstab
sudo vim /root/.credentials.NW-HD-1TB

# and write the following to this file:
username=admin
password=yourpassword

# Remove default privileges for this file (644 - everyone can see it)
sudo chmod 600 /root/.credentials.NW-HD-1TB

# edit the fstab file
sudo vim /etc/fstab

# and add the following at the end of the file:
//192.168.X.Y/share/ /media/NW-HD-1TB   cifs  auto,credentials=/root/.credentials.NW-HD-1TB,iocharset=utf8,uid=bruno,gid=users,file_mode=0775,dir_mode=0775 0 0

# you are done!

# next time you reboot, it will be there, but you can also check if everything went fine by typing (to re-mount everything on fstab)
sudo mount -a


Final notes (about references):
  • The references where I learned this from get confused on the Ubuntu users and the HD server users. They are not related at all. For instance, the "admin" user I am using does not even exist in my ubuntu.
  • The credentials file is a MUST, but place a more specific name (something like: credentials-hd1) unless you plan to use a single one for every similar operation you need in fstab.

 BRAGA, Bruno

 



Brazilian currently based in Japan, working on Information Technology.