How to Set Up an NFS Mount on CentOS 6



NFS stands for Network File System and they are typically used to share directories between several servers. It helps in optimizing the disk space usage by keeping home directory on one server and others connecting it through the network. The machine which hosts the shared network is known as the server and the machines that connect to it are called clients.

This tutorial will guide you in setting up NFS mounts. First we will set up the server machine. For example, let’s assume the IP addresses of server and client are and respectively. Also, both the machines should be set up as root. You can access the root user using the sudo su command.

NFS Server Set Up


Firstly, we will be downloading the required software using command line. You can start by installing nfs programs using the apt-get command as shown below:

yum install nfs-utils nfs-utils-lib

After it is installed, run the scripts for NFS server using the commands:

chkconfig nfs on 
service rpcbind start
service nfs start

Once it is completed, we can proceed with the export of shared directory.

For that, first decide which directory you would like to share with client. Then, that directory should be added to /etc/exports file which has the specification of directory as well as how it is to be shared. Suppose, you want to share /home directory. Export the directory and add the following lines of code to the end of the file.

vi /etc/exports

Here is an explanation of the terms used in the above command:

  • rw option allows the client machines to both read and write within the shared directory.
  • Sync will confirm requests to shared directory once changes are committed.
  • No_subtree_check option is for preventing the subtree checking. NFS has a feature where it scans each and every directory above it whenever a shared directory happens to be a subdirectory of a larger file system. The no_subtree_check option increases the reliability but reduces security.
  • no_root_squash option allows the root to make connection with the designated directory.


Finally, you can export the directory using:

exportfs -a


NFS Client Set Up


Start with, install the nfs programs using apt-get command:

yum install nfs-utils nfs-utils-lib

After that, create a directory for NFS shared files as shown below:

mkdir -p /mnt/nfs/home

And then, mount it as:

mount /mnt/nfs/home

Verify whether the directory has been mounted using the df –h command. You should see it on the list displayed:

df -h
Filesystem            Size  Used Avail Use% Mounted on

/dev/sda               20G  783M   18G   5% /       20G  785M   18G   5% /mnt/nfs/home

You can also use the mount command to view all the mounted file systems:

/dev/sda on / type ext4 (rw,errors=remount-ro)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw) on /mnt/nfs/home type nfs (rw,noatime,nolock,bg,nfsvers=2,intr,tcp,actimeo=1800,addr=


Verify the NFS Mount


Once you have mounted the NFS directory, you can verify it by creating a file on the client and checking it from the server.

Create a sample file:

touch /mnt/nfs/home/example

If you check it on the server  /home directory, you should be able to find that file:

ls /home

In order to ensure that the mount is active always, you can add the directory to the fstab file on your client. Then, whenever server reboots, mount will start up.

vi /etc/fstab  /mnt/nfs/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

The following command comes handy for mounting directories specified in fstab file:

mount -a


Removing NFS Mount


In case if you want to remove a directory, you can do that using the umount command as follows:


sudo umount /directory name

Verify the filesystem using df –h command to see if thee mounts were removed.

KB Admin has written 46 articles