How to Setup NFS in Ubuntu

This tutorial shows step-by-step how to setup NFS (Network File System).
Use this tutorial in conjunction with my YouTube video: How to Setup NFS File Shares in Ubuntu

NFS Server

Install NFS Package on your Ubuntu Server

sudo apt-get install nfs-kernel-server

Create Folder List to Share

This example I will be sharing my whole RAID folder with any user (except root) in my LAN.

sudo nano /etc/exports

Add the following line to the end of the exports file.
The spacing is very important, e.g. there is no space between the IP address and Options list.

/mnt/raiddisk	192.168.1.0/255.255.255.0(rw,sync,root_squash,subtree_check)

Start NFS Service
sudo service nfs-kernel-server start

If all is well you will see the message:

* Exporting directories for NFS kernel daemon...      [ OK ]
* Starting NFS kernel daemon                          [ OK ]

Otherwise if there is an error you can stop the NFS service, and then go back and edit the Export list.

sudo service nfs-kernel-server stop
NFS Clients

Install NFS Client Package

sudo apt-get install nfs-common

Create Mount Point

You could either create a mount point under the /mnt folder, or use your home folder.
Here is how to create a folder under /mnt:

sudo mkdir /mnt/nfsmount

Edit fstab

(Substitute nano for your favorite text editor)

sudo nano /etc/fstab

Add the following line to the end of the fstab file:

ServerIP:/ServerFolder	ClientFolder	nfs	Options	dump	pass

For Example:

192.168.1.100:/mnt/raiddisk	/mnt/nfsmount	nfs	rw,soft,intr,noatime,timeo=100,rsize=32768,wsize=32768	0	2

Options List:
  • rw - Mount the filesystem as read / write.
  • soft / hard - Determines the recovery behaviour of the NFS client when an NFS request times out. Hard retries indefinitely, Soft returns an error to the calling application.
  • intr - Allows NFS requests to be interrupted if the server goes down or cannot be reached
  • atime / noatime - Determines whether the Last Access time is modified when opening a file on a Linux filesystem. Reducing the number of file writes can result in a measurable performance gain.
  • noexec - Prevents execution of binaries on mounted file systems. This is useful if the system is mounting a non-Linux file system via NFS containing incompatible binaries.
  • timeo=n - The time in deciseconds (tenths of a second) the NFS client waits for a response before it retries an NFS request.
  • retrans=n - The number of times the NFS client retries a request before it attempts further recovery action. Default is three times.
  • rsize=n - The maximum number of bytes in each network READ request that the NFS client can receive when reading data from a file on an NFS server. Largest read payload supported by the Linux NFS client is 1,048,576 bytes (one megabyte). The rsize value is a multiple of 1024.
  • wsize=n - As above, but for WRITE requests instead of READ requests.

Further information is available from the man page

Now to Try it out
sudo mount -a

If all being well you won't see any messages
You will only need to use mount -a once, next time you reboot your system will automatically mount the NFS File Share.