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.
Announcement
You can find all my latest posts on medium.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:
$ yum install nfs-utils
$ showmount -e The-Server
$ yum install samba-client cifs-utils
$ smbclient -L The-Server –-user vagrant
$ mkdir -p /nfs/{server-name}/{mountpoint}
$ mount -t nfs The-Server:/nfs/Shared-Folder /nfs/The-Server/Shared-Folder
$ mkdir -p /cifs/The-Server/Shared-Folder
$ 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.
$ mount
# or
$ df -h