How to Setup NFS Server in Ubuntu (Linux)

nfsNFS (Network File System) is a way of sharing the ‘directories’ on a network with another Computers on that network. The computer which enables the file sharing is called the “Server” and the other computer which request the shared folder or files are called the “Clients”. This approach is beneficial if :

  1. Multiple People want to access the same files or Folders in a network.
  2. You want to extend the Storage Size of Current Computers having low space SATA or regular Hard Drives installed.

NFS helps you to create a Network Storage Area (NAS) in Linux/Unix environment and it is most welcomed by Microsoft and MAC OS Clients.

In this article, I will show you that how to setup NFS Server in Ubuntu. If you have different Linux OS installed, the package management could be different (i.e. yum install instead of apt-get), however the rest of the steps will be pretty much same.

Please note that you may find this article bit longer, however I will try to keep it as short as possible and will cover the basics.

Let’s get started, then. We will need following Packages:

  1. nfs-kernel-server             #NFS Server configuration package
  2. rpcbind                             #to make rpc calls
  3. nfs-client                          #nfs package for clients to communicate to the NFS Server

Installation and Configuration

Make sure your Ubuntu repository list is up to date with the latest package information, if not, type the following command:

sudo apt-get update && sudo apt-get upgrade -y

Now its time to install the NFS Server and nfs-common package. You can do that in a single line command or individually as well.

sudo apt-get install nfs-kernel-server rpcbind nfs-common -y

During the installation, you might get an error /export or /exports directory doesn’t exist, can not start the server. Don’t worry about it for now and you can simply ignore it.

You can choose to share a particular directory or the Users Home Directories from /home/users. For this setup we will be sharing a directory called users under /export directory. Let’s first create a users direcotry within the /export directory. If you want to share all home directories of all existing users then you will have to mount /home/ at a single point using --bind flag along with the mount command.

sudo mkdir -p /export/users

and give the 0777 permissions to this directory so everyone will be able to read/write/execute the files.

There are 3 Configuration files associated to the NFS-Server and these are under /etc/default/nfs-common, /etc/default/nfs-kernel-server and /etc/exports. Let’s configure them in the next Section.

Share your thoughts