In the previous article, we discussed how to install and configure NFS Server on RHEL / CentOS 8. This guide is the gorge for the missing piece. Here we will configure our client systems to access a remote NFS share.
NFS enables client systems to access files that are stored on a remote shared server over a network and make use of those file systems as if they are locally mounted.
Step 1: Install and Configure NFS server
We’ll refer to our previous setup which looks like below.
|NFS Server||RHEL/CentOS 8||172.16.54.136||server.example.com|
|NFS Client 1||RHEL/CentOS 8||172.16.54.136||client1.example.com|
|NFS Client 2||RHEL/CentOS 8||172.16.54.131||client2.example.com|
The IP addressing will be different for your setup, so replace network parameters with yours when setting up NFS server and client.
For NFS server setup, refer to Install and Configure NFS Server on CentOS / RHEL 8
Step 2: Install NFS Client on CentOS / RHEL 8
Add NFS server DNS record to /etc/hosts file on your clients.
$ sudo vi /etc/hosts 172.16.54.136 nfs-server
Check if the server is reachable via name added.
$ ping -c 1 nfs-server PING nfs-server (172.16.54.136) 56(84) bytes of data. 64 bytes from nfs-server (172.16.54.136): icmp_seq=1 ttl=64 time=0.693 ms --- nfs-server ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.693/0.693/0.693/0.000 ms
NFS server and client share the same parent package. The name of the package to be installed is nfs-utils. Install it on your servers to access NFS server shares.
sudo yum -y install nfs-utils
Step 3: Mounting NFS Share on the Client
We had configured NFS Share earlier, this is what we will mount on the client
Discovering NFS exports
Before we can mount, let’s discover NFS exports on NFSv3 or NFSv4 server.
With any server that supports NFSv3, use the showmount utility:
$ sudo showmount --exports nfs-server Export list for nfs-server: /data/nfshare 172.16.54.0/24
nfs-server can be replaced with NFS server IP address if name resolution is not set.
If NFS server is configured with only NFS v4 support, then mount the root directory and look around for available folder shares.
$ sudo mount nfs-server:/ /mnt/ $ sudo yum install -y tree $ tree /mnt/ /mnt/ └── data └── nfshare 2 directories, 0 files
On servers that support both NFSv4 and NFSv3, both methods work and give the same results.
Mounting an NFS share with mount
The mount utility can be used to mount an NFS share with the following command:
mount -t nfs -o options host:/remote/export /local/directory
- options is a comma-delimited list of mount options.
- host is the host name, IP address, or fully qualified domain name of the NFS server exporting the file system to be mounted.
- /remote/export is the file system or directory being exported from the server, i.e, directory to be mounted.
- /local/directory is the client location where /remote/export is mounted.
In our example, this will be:
sudo mount -t nfs -o nfsvers=4 nfs-server:/data/nfshare /mnt
$ df -hT | grep /mnt nfs-server:/data/nfshare nfs4 20G 175M 20G 1% /mnt
To see all mount options, refer to man pages.
man mount man nfs
To persist the changes across system reboots, Configure NFS mounting on /etc/fstab.
sudo vi /etc/fstab
Add a line like with the following syntax to the end of file.
host:/remote/export /local/directory nfs defaults 0 0
In my case, this will be.
nfs-server:/data/nfshare /mnt nfs defaults 0 0
Test your settings.
$ sudo umount /mnt $ sudo mount -a $ df -hT | grep /mnt nfs-server:/data/nfshare nfs4 20G 175M 20G 1% /mnt
Try write files to the directory.
echo "Test file1" >/mnt/testfile1 echo "Test file2" >>/mnt/testfile1
The file should be seen on the NFS server block device.
$ tree /data/nfshare/ /data/nfshare/ └── testfile1 0 directories, 1 file $ cat /data/nfshare/testfile1 Test file1 Test file2
Kudos!. You have configured NFS client successfully on a CentOS/RHEL system. Stay connected for more informative guides as you go through: