Set up NFS Share on Ubuntu 16.04 LTS

Install & Configure NFS Server

NFS stands for Network File System. This tutorial is going to show you how to configure NFS share on Ubuntu 16.04 so that other computes in your local network can access files and directories on the Ubuntu 16.04 system. We will see how to configure the server side and the client side.

NFS allows directories and file systems to be shared across a local network. NFS can also be set up over the Internet but it’s not secure. In this tutorial, we will set up NFS file share in a home network with two Ubuntu 16.04 computers.

Make sure you are running
 commands as the root user.

On the first Ubuntu 16.04 computer, install nfs-kernel-server packages.

root@pemulalinux:~# apt-get -y install nfs-kernel-server

Let’s create a directory we want to share with client machines. Here, we will create a new directory named /var/nfsshare .

root@pemulalinux:~# mkdir /var/nfsshare

Allow client machines to read and write to the created directory.

root@pemulalinux:~# chmod 777 /var/nfsshare

Then edit the exports file with nano text editor. The exports files tell NFS server which directories or file systems will be shared to client.

root@pemulalinux:~# vi /etc/exports

The syntax is as follows

/path/to/directory     client-IP address(options)

For example, you want to share you home directory or another directory to the second Ubuntu computer with IP address 10.150.100.17, then put the following line at the end of the file, then save the configuration.

/var/nfsshare 10.150.100.0/24(rw,sync,no_subtree_check)

You can get to know all the option on the man page (man exports) or here.
Use the below command to export the shared directories.

root@pemulalinux:~# exportfs -ra

Configure NFS client

We need to install the nfs-common package on the client machine to mount a remote filesystem.

Make sure you are running commands as the root user.

root@ubuntu:~# apt-get -y install nfs-common

Create a directory /var/nfsshare on the client machine to mount the shared directory.

root@ubuntu:~# mkdir /var/nfsshare

Use mount command to mount a shared directory /var/nfsshare from NFS server (10.150.100.16) in /var/nfsshare on the client machine.

root@ubuntu:~# mount -t nfs 10.150.100.16:/var/nfsshare /var/nfsshare

Verify the mounted share on the client machine using the mount command.

root@ubuntu:~# mount | grep nfs

Output:

You can also use df command to check the mounted NFS shares.

root@ubuntu:~# df -hT

Output:

Automount NFS Shares

To mount NFS shares automatically on every reboot, you need to edit /etc/fstab file on your client system.

root@ubuntu:~# vi /etc/fstab

Add the below line at the end of the file.

10.150.100.16:/var/nfsshare /var/nfsshare defaults 0 0

Save and close the file.

Reboot the client machine and check whether NFS share is automatically mounted or not.

root@ubuntu:~# reboot

Leave a Reply

Your email address will not be published. Required fields are marked *