How to Configure/Setup NFS client on CentOS 8

Share this article

In one of the previous articles, How to install & configure NFS Server on CentOS 8 we set up a NFS server in CentOS 8. In this article, we will further discuss how to configure the NFS client on CentOS 8.

Our setup.

The below-mentioned image shows a depiction of our NFS infrastructure setup.

  • NFS server:
    • IP : 192.168.122.105
    • Hostname : test.nfs-server
    • OS: CentOS 8
  • NFS Client1 :
    • IP: 192.168.122.207
    • Hostname: test.nfs-client-centos
    • OS: CentOS 8
  • NFS Client2:
    • IP: 192.168.122.1
    • Hostname: test.nfs-client-ubuntu
    • OS: Ubuntu 20.04

In this article, we will setup NFS client1 which will be running on CentOS 8. For NFS client2 you can refer to How to Configure/Setup NFS client on Ubuntu 20.04 article.

Install NFS client

In order to install the NFS client, it uses the same nfs-utils package. Install the package by using below mention command.

sudo dnf install nfs-utils -y 

Verify the installation

After installing the nfs-utils package. You need to start the nfs-server service by yourself.

To start and enable the nfs-server use the following commands.

sudo systemctl start nfs-server.service
sudo systemctl enable  nfs-server.service

When you are starting the nfs-server service it won’t show you any output if it is successful. While enabling the nfs-server service it will create the symlink. Below mentioned code section shows the successful enabling output of nfs-server service.

[foofunc@test root]$ sudo systemctl enable  nfs-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service.
[foofunc@test root]

Run the following command to check the status.

sudo systemctl status nfs-server.service

The above command will show you the below output if it is running successfully.

[foofunc@test ~]$ sudo systemctl status nfs-server.service
[sudo] password for foofunc: 
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
   Active: active (exited) since Wed 2021-09-08 16:24:26 EDT; 5min ago
 Main PID: 27190 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 23956)
   Memory: 0B
   CGroup: /system.slice/nfs-server.service

Sep 08 16:24:26 test systemd[1]: Starting NFS server and services...
Sep 08 16:24:26 test systemd[1]: Started NFS server and services.
[foofunc@test ~]$ 

Miscellaneous configuration

/etc/hosts entry

This conf is totally optional. If you are using a local DNS name (admin uses it for simplicity) in your mount configuration then it is important to have it. Enter the following line into /etc/hosts file

192.168.122.105 test.nfs-server

Verify the above entry by running ping command. If it is able to ping the nfs-server that means the client is able to resolve the entry.

[foofunc@test ~]$ ping test.nfs-server -c 4 
PING test.nfs-server (192.168.122.105) 56(84) bytes of data.
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=1 ttl=64 time=0.452 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=2 ttl=64 time=0.461 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=3 ttl=64 time=0.468 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=4 ttl=64 time=0.545 ms

--- test.nfs-server ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3061ms
rtt min/avg/max/mdev = 0.452/0.481/0.545/0.037 ms
[foofunc@test ~]$ 

Create directory for mounting

For the sake of simplicity, I will create a directory in the /mnt/ where I will mount the share from the nfs-server.

mkdir -p /mnt/mount_test

NFS share/export mounting

Verify the export list

Check the export list for the nfs-server. Use the following command.

showmount --exports <ip_address/Host_name of the nfs-server>

See the command output:

[foofunc@test ~]$ sudo showmount --exports test.nfs-server
Export list for test.nfs-server:
/mnt/export/demo 192.168.122.201
[foofunc@test ~]$ 

Mount the NFS Share

The mount package is used to mount the NFS share. mount package is by default available in Linux.

Run the following command to mount the remote share directory,

mount -t nfs -o options <nfs-server:/remote/share_directory>  </local/mount_directory>

The above command use the following options

  • -t: is used to indicate the filesystem type. For that we have mentioned type of file system is nfs
  • -o : Use the specified mount options. Multiple options can be passed with comma.
  • nfs-server:/remote/share_directory: nfs-server share directory which we are going to mount on our client machine.
  • /local/mount_directory: this arument is path to local directory which will be the mointing point in client machine.

Following command, I have run to mount the share for nfs-server

[root@test ~]# mount -t nfs -o nfsvers=4 test.nfs-server:/mnt/export/demo /mnt/mount_test
[root@test ~]#

Verify

In order to check the filesystem and mounted point use the df command.

[root@test ~]# df -kh
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  856K  797M   1% /run
/dev/mapper/ubuntu--vg-centos--lv   20G  9.6G  9.1G  52% /
tmpfs                              3.9G   64K  3.9G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                          976M  220M  690M  25% /boot
tmpfs                              798M     0  798M   0% /run/user/0
test.nfs-server:/mnt/export/demo    50G   12G   39G  24% /mnt/mount_test
[root@test ~]# 

Make mounting persistent

In the previous section, we have done the mounting but this mount is not persistent which means if we reboot the system after reboot we will don’t have NFS filesystem in our client machine. Therefore, to make it persistent we need to do entry in /etc/fstab.

Syntax for /etc/fstab entry

 nfs-server:/remote/share_directory /local/mount_directory   nfs defaults   0 0

In our case we have following entries in the /etc/fstab file.

[root@test ~]#  cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-yyCJpEJ7umYY6MjNBb79mpYchXJDdFsN515fWkIaf2k8u6AGoM7OkFjlPTOTaXYv / ext4 defaults 0 0
# /boot was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/35d3eb20-f0ae-4833-b3ef-55595e77b5c4 /boot ext4 defaults 0 0
/swap.img	none	swap	sw	0	0
test.nfs-server:/mnt/export/demo /mnt/mount_test nfs defaults   0 0
[root@test ~]#  

The easiest way to check the validity is to reboot the system or you can unmount or then use /etc/fstab entry to mount the filesystem. Use the following command to reboot or do the unmount and then again mount with fstab entry.

sudo reboot 

or

sudo umount /mnt/mount_test
sudo mount -a

Verify

In order to check the filesystem and mounted point use the df command.

[root@test ~]# df -kh
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  856K  797M   1% /run
/dev/mapper/ubuntu--vg-centos--lv   20G  9.6G  9.1G  52% /
tmpfs                              3.9G   64K  3.9G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                          976M  220M  690M  25% /boot
tmpfs                              798M     0  798M   0% /run/user/0
test.nfs-server:/mnt/export/demo    50G   12G   39G  24% /mnt/mount_test
[root@test ~]# 

Summary

In this article, we have explained how to set up the NFS client and how to mount the NFS filesystem. This article is the next part of How to install & configure NFS Server on CentOS 8.

In case you face any issues running the command feel free to comment.

Leave a Comment

Your email address will not be published. Required fields are marked *