Date Posted: 28-02-2017

NFS(Network File system) used to mount remote files to the server. In this post, we will cover up on how to setup NFS server and mount the NFS directory to the client server.

Assumption:

1.  Ubuntu Server. One server is Ubuntu Server used for NFS server and second ubuntu server is used to mount the NFS point.

Implementation:

We will start with building NFS server. Let’s start by installing NFS server on the server.

apt-get install nfs-kernel-server

Create a directory for nfs mount point.

mkdir /nfsshare

Change the ownership and groupname of the directory.

chown nobody:nogroup /nfsshare

Open the file /etc/exports file and add the following line.

vi /etc/exports

/nfsshare 172.0.0.0/8(rw,sync,no_root_squash,no_subtree_check)

Where,

172.0.0.0/8 – We can replace this IP address with the IP address which we will be connecting. We can mention either single IP address or IP address range.

rw – this option is used to read write files on the client machine.

sync – This option forces nfs to write changes before sending data.

no_root_squash – This was intended as security feature to prevent a root account on the client from using the file system of the host as root

no_subtree_check – This option disables subtree checking. If a subdirectory of a filesystem is exported, but the whole filesystem isn’t then whenever a NFS request arrives, the server must check not only that the accessed file is in the appropriate filesystem (which is easy) but also that it is in the exported tree (which is harder). This check is called the subtree_check.

Start the nfs server service.

systemctl restart nfs-kernel-server

Client Side NFS Configuration:

So, far we have installed NFS server. Now, its time to mount the partition to the client machine.

Install the nfs-common on the client machine.

apt-get install nfs-common

As an example, we are going to create a directory called /nfs and mount to nfs drive from remote server.

mkdir /nfs

mount -t nfs  xx.xx.xx.xx:/nfsshare /nfs

where,

xx.xx.xx.xx is the nfs server IP address.

Make a permanent entry on /etc/fstab so that it automatically mounts whenever the boots up.

vi /etc/fstab

xx.xx.xx.xx:/       /nfs    nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

Testing:

Execute the command df -h to view the mounted partition

df -h

To unmount the partition, use the below command

umount /nfs

Since we already added the mount partition on fstab, it will automatically mount the partition. Test the same by using mount -a command

mount -a

 

Leave a Reply