NFS – How to set up an NFS client on CentOS/RHEL 7

Network Files System (NFS) is a protocol that let’s one Linux box (NFS server) to share a folder with another Linux box (NFS Client). On the NFS client this shared folder looks like just an ordinary folder. NFS only works in an internal network so you can share folders over the public internet.

This article doesn’t cover how to setup an NFS server, instead we will assume that we already have an NFS server already setup and we want to configure an NFS client to connect to it. We created a NFS vagrant project on github to help you following along with this example. In our example we have:

+--------------------------+              +--------------------------+
|                          |              |                          |
|       nfs-storage        |              |        nfs-client        |
|     (IP: 10.0.6.10)      |              |                          |
|                          |              |                          |
|                          |              |                          |
|                          |              |                          |
|                          |              |                          |
|   +-----------------+    |              |     +---------------+    |
|   | /nfs/export_ro  |<----------------------->| /mnt/ref_data |    |
|   +-----------------+    |              |     +---------------+    |
|                          |              |                          |
|   +-----------------+    |              |     +---------------+    |
|   | /nfs/export_rw  |<----------------------->| /mnt/backups  |    |
|   +-----------------+    |              |     +---------------+    |
|                          |              |                          |
|                          |              |                          |
+--------------------------+              +--------------------------+

With the vagrant project, the nfs server (nfs-storage) will already be set up for you. So you just need to make configure the nfs client to access the 2 NFS folders made available by nfs-storage.

To start with, on NFS client you install:

[root@nfs-client mnt]# yum install nfs-utils

Next see if you your client can query for available exports:

[root@nfs-client mnt]# showmount -e 10.0.6.10
Export list for 10.0.6.10:
/nfs/export_rw *
/nfs/export_ro *

Next we’ll try to mount these, first we need to create mount-points for these exports:

$ mkdir -p /mnt/backups
$ mkdir -p /mnt/ref_data

Now we can mount them (non-persistently) using the mount command:

[root@nfs-client ~]# mount -t nfs 10.0.6.10:/nfs/export_ro /mnt/ref_data
[root@nfs-client ~]# mount -t nfs 10.0.6.10:/nfs/export_rw /mnt/backups

You can confirm this has worked by running either of the following commands:

$ mount 
# or
$ df -h

Now you can try creating content inside the mount-points and will.

Automount NFS folders

We can NFS mounts persistant by adding an entry to the /etc/fstab file:

10.0.6.10:/nfs/export_ro   /mnt/ref_data   nfs   soft,timeo=100,_netdev,ro   0   0
10.0.6.10:/nfs/export_rw   /mnt/backups    nfs   soft,timeo=100,_netdev,rw   0   0

Note you can find more option about nfs mount options here:

$ man nfs

# also see the following for more general mount options:

$ man mount

Here we used ‘soft’ to make the mounting to error out rather than hanging (although this can cause data corruption). Also we set (timeo)ut to 100 deciseconds (10 seconds). Now we test this by running:

$ mount -a

you can then do mount or df -h.

Note: you can also automount, such as using a tool called autofs, or creating a custom systemd target. Also might be able to use a tool called sshfs too.

Try the RHCSA quiz

By the end of this article you should be able to answer the following questions:

In this quiz we’ll assume that we have created 2 mount points /mnt/backups and /mnt/ref_data. Also our NFS server’s ip address is 10.0.6.10.


What is the command to install the nfs client side packages?

$ yum install nfs-utils

What is the command to check what folders our NFS server has made available?

$ showmount -e 10.0.6.10

What is the command to manually mount these folders?

$ mount -t nfs 10.0.6.10:/nfs/export_ro /mnt/ref_data
$ mount -t nfs 10.0.6.10:/nfs/export_rw /mnt/backups

What command can you run to check mount command has worked?

$ mount
# or
$ df -h
# note: lsblk wont list these since they lsblk only lists locally attached devices.

What entries do we need to add to the fstab file to make these 2 mounts persistant?

10.0.6.10:/nfs/export_ro /mnt/ref_data nfs soft,timeo=100,_netdev,ro 0 0
10.0.6.10:/nfs/export_rw /mnt/backups nfs soft,timeo=100,_netdev,rw 0 0