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:


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

$ yum install nfs-utils

02. What is the command to check what folders the server 'The-Server' is sharing via nfs?

$ showmount -e The-Server

03. What is the command to install the CIFS/Samba client side packages?

$ yum install samba-client cifs-utils

04. What is the command to check what folders the server 'The-Server' is sharing via CIFS/Samba by querying as the user 'vagrant'?

$ smbclient -L The-Server -user vagrant

05. What is the command to create logical folder structure for an NFS mountpoint?

$ mkdir -p /nfs/{server-name}/{mountpoint}

06. What is the command to manually mount onto the mountpoint, '/nfs/The-Server/Shared-Folder' the nfs share, '/nfs/Shared-Folder' that has been made available by the server 'The-Server'?

$ mount -t nfs The-Server:/nfs/Shared-Folder /nfs/The-Server/Shared-Folder

07. What is the command to create logical folder structure for an CIFS mountpoint, assuming the nfs server is called 'The-Server' and the folder being shared out is called 'Shared-Folder'?

$ mkdir -p /cifs/The-Server/Shared-Folder

08. What is the command to manually mount onto the mountpoint, '/cifs/The-Server/Shared-Folder' the cifs share, 'Shared-Folder' that has been made available by the server 'The-Server', where the smb username is 'vagrant', and corresponding password is 'admin'?

$ mount -t cifs -o user=vagrant,password=admin //The-Server/Shared-Folder /cifs/The-Server/Shared-Folder
# Note, you must use the double-slash syntax.

09. What two commands can you run to check the cifs or nfs mount has worked?

$ mount
# or
$ df -h