Install and configure NFS server on Ubuntu for serving files

When it comes to serving media content within your local network, a NFS share is way better than Samba/CIFS share in terms of speed and resource usage. If you have a XBMC box to watch TV shows and movies from a central server then a Network File System (NFS) share should be the choice for a media source. It only takes a few minutes to install and configure NFS server in Ubuntu, and it is a must have item on my server.

Setup NFS Server on Ubuntu

If you do not have NFS yet, you will have to install NFS server first using the following commands:

sudo apt-get install nfs-kernel-server

That’s the easiest part. It requires just bit more effort to configure NFS server to share files with right permissions.

Configure NFS Server

After installation you can configure NFS server by editing the /etc/exports file. First make a backup copy of the default NFS configuration file:

sudo cp -a /etc/exports /etc/exports.backup

Then open the /etc/exports file using the following command:

sudo nano /etc/exports

Edit and comment out all existing lines by adding a “#” in front the line. Next, setup NFS share for each folder you want to make available to the client devices as shown below.

Setup NFS Share for Media

One of the primary purposes I configure NFS server on Ubuntu server is to share my media to all my Xbian Raspberry Pi HTPC. As I said before, for sharing within a network the performance of NFS is better than SAMBA. If you a media folder on your central Ubuntu server, then add the following line to line to /etc/exports to setup NFS share for it.

#Export media to all IP address under 192.168.1.X
/home/user/media   192.168.1.0/24(rw,async,insecure,no_subtree_check,nohide)

This will make your media folder located under /home/user available to every device in your local network. The options within parenthesis are specifically chosen to improve performance. We are sharing “non-critical” media files and we are making them available only to devices in your home network (192.168.1.X). So we can afford to go lower on security to improve speed and performance.

rw – allows read/write if you want to be able to delete or rename files from XBMC or other devices. On XBMC you write permission to download subtitles.
async – Increases read/write performance. Only to be used for non-critical files.
insecure – Does not mean the files are insecure but rather this setting allow clients (eg. Mac OS X) to use non-reserved ports connect to a NFS server.
no_subtree_check – Improves speed and reliability by eliminating permission checks on parent directories.
nohide – This option allows the client device to see multiple file systems but only works on one host. Since this is rare, you may choose to omit this option as it can potentially cause problems in some cases.

Starting, Stopping, and Restarting NFS Server

Once you have setup NFS server, you can start NFS share using the following command:

sudo exportfs -ra

Any time you make changes to /etc/exports I recommend that you restart your NFS server using the following command:

sudo service nfs-kernel-server restart

On your XBMC just choose Network Filesystem (NFS) when you select the source. Note that NFS does not work on Windows clients but they should work on all Linux-based OSes that run XBMC. For Windows, you will still have to Setup Samba as the file server.

Setup NFS Client on Ubuntu

If you would like to connect to the NFS server on your local computer running Linux – prefferably Ubuntu, Do the following:

sudo apt-get install nfs-common

Mounts

Check to see if everything works
You should try and mount it now. The basic template you will use is:

sudo mount ServerIP:/folder/already/setup/to/be/shared /home/username/folder/in/your/local/computer

so for example:

sudo mount 192.168.1.42:/home/music /home/nerd/music

Mount at startup

Add the following lines in your fstab to mount NFS directories automatically after system reboot.

sudo nano /etc/fstab

This will mount directories on start up after the server reboots.

Server_IP:/home/music /home/nerd/music  /mnt/music   nfs   auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Conclusion
NFS provides a quick and easy way to access remote systems over a network. However, the protocol itself is not encrypted. If you are using this in a production environment, consider routing NFS over SSH or a VPN connection to create a more secure experience.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s