24/7/365 Support

Installing Network File System in Ubuntu

Network File System (NFS) is a distributed filesystem protocol that allows clients to access remote files and directories as if they are available on the local system. This allows client systems to leverage large centrally shared storage. Users can access the same data from any system across the network. A typical setup for NFS includes a server that runs the NFS daemon, nfsd, and lists (export) files and directories to be shared. A client system can mount these exported directories as their local file system.

In this recipe, we will learn how to install the NFS server and client systems.

Getting ready

You will need two Ubuntu systems: one as a central NFS server and another as a client. For this recipe, we will refer to the NFS server with the name Host and the NFS client with the name Client. The following is an example IP address configuration for the Host and Client systems:

Host - 10.0.2.60

Client - 10.0.2.61

You will need access to a root account on both servers, or at least an account with sudo privileges.

How to do it…

Follow these steps to install NFS:

First, we need to install the NFS server:

$ sudo apt-get update

$ sudo apt-get install nfs-kernel-server

Create the directories to be shared:

$ sudo mkdir /var/nfs

Add this directory to NFS exports under /etc/exports:

$ sudo nano /etc/exports

Add the following line to /etc/exports:

/var/nfs *(rw,sync,no_subtree_check)

Save and close the exports file.

Now, restart the NFS service:

$ sudo service nfs-kernel-server restart

Next, we need to configure the client system to access NFS shares.

Create a mount point for NFS shares.

Install the nfs-common package on the client side:

$ sudo apt-get install nfs-common

$ sudo mkdir -p /var/nfsshare

Mount the NFS shared directory on the newly-created mount point:

$ sudo mount 10.0.2.60:/var/nfs /var/nfsshare

Confirm the mounted share with the following command:

$ mount -t nfs

Now, change the directory to /var/nfsshare, and you are ready to use NFS.

How it works…

In the preceding example, we have installed the NFS server and then created a directory that will share with clients over the network. The configuration file /etc/exports contains all NFS shared directories. The syntax to add new exports is as follows:

directory_to_share client_IP_or_name(option1, option2, option..n)

The options used in exports are as follows:

rw: This enables read/write access. You can enable read-only access with the ro option.

sync: This forces the NFS server to write changes to disk before replying to requests. sync is the default option; you can enable async operations by explicitly stating async. Async operations may get a little performance boost but at the cost of data integrity.

no_subtree_check: This disables subtree checking, which provides more stable and reliable NFS shares.

You can check the exports documentation for more export options. Use the man command to open the exports manual pages, as follows:

$ man exports

In the preceding example, we have used the mount command to mount the NFS share. Once the client system has restarted, this mount will be removed. To remount the NFS share on each reboot, you can add the following line to /etc/fstab file:

10.0.2.60:/var/nfs /var/nfsshare nfs4 _netdev,auto 0 0

To mount all shares exported by the NFS server, you can use the following command:

$ sudo mount 10.0.2.60:/ /var/nfsshare

There's more…

NFS 4.1 adds support for pNFS, which enables clients to access the storage device directly and in parallel. This architecture eliminates scalability and performance issues with NFS deployments.

See also

NFS exports options at http://manpages.ubuntu.com/manpages/trusty/man5/exports.5.html

Parallel NFS at http://www.pnfs.com/

NFS documentation in manual pages, by using the following command:

$ man nfs

Help Category:

What Our Clients Say