Sunday, 23 December 2012

HOWTO: Build Your Own NAS

Here is the scenario, you have a Debian/Ubuntu server and you want to share files to other clients on your LAN.

This is a very simple process.

Section 1: Setting up a directory to share

1) Create a group "nfs", this group will define the users who can read and write to the share;

sudo addgroup nfs

2) Add a user to the group;

sudo usermod -a -G nfs brett

3) Create a directory for your shared files. I will create a directory called "store"

sudo mkdir /store

4) Change its group ownership to our "nfs" group

sudo chgrp nfs /store

5) Change permissions to allow the "nfs" group full access (and deny everyone else);

chmod 770 /store

Achievement check: You should be able to create files in /store while logged in as a local user who is a member of the "nfs" group.

Section 2 : Sharing with NFS server

1) Install NFS server;

sudo apt-get install nfs-kernel-server

2) Edit the exports file;

sudo vi /etc/exports

Create a simple read/write share that any network host may connect to. Add this line to the end of the file;

/store *(rw,sync,no_subtree_check,no_root_squash)

3) Restart the NFS server

sudo service nfs-kernel-server restart

Section 3 : Connecting with a client

To complete this section, you will need to be able to ping your server from the client using an IP address or DNS name. If you can't then there is no point continuing. My server name is "nas"

1) On your client, confirm that you can ping your server;

ping nas 
PING nas ( 56(84) bytes of data.
64 bytes from nas ( icmp_req=1 ttl=64 time=3.22 ms

2) Create a directory to mount the share on. We will use a directory called "nasmount" here but you can use anything you like;

sudo mkdir /nasmount

2) Edit your fstab file;

vi /etc/fstab

Add this line to the end , replacing the servername (nas) with the IP or name of your server;

nas:/store /nasmount nfs rw,defaults 0 0

3) Mount the share;

sudo mount /nasmount

4) Verify that the share is mounted using df

df -h
nfs:/nasmount            11G   11G  255M  98% /nasmount

Achievement Check: You should be able to create and delete files in the shared directory from the client*.

* You will need to use a user account on the client with the same UID as the account we set up earlier on the server. In this example the user account was "brett" with a UID of 1000. You can use something like LDAP to centrally manage user accounts across a network if you have a lot of users.

No comments: