How to setup NFS (Network File System) on RHEL/CentOS

We need to install NFS packages on the NFS Server as well as on NFS Client machine. We can install it via “yum” for RHEL/CentOS.

On the NFS server side, run the following commands to setup NFS server.

$ systemctl status nfs
$ mkfs.ext4 /dev/nvme9n1
$ mkdir /mnt/nfsshare

$ vim /etc/exports
/mnt/nfsshare 10.10.10.1(rw,no_root_squash)

$ systemctl restart nfs
$ exportfs -s
/mnt/nfsshare  10.10.10.1(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

On the NFS client side, run the following command to mount the exported NFS share.

$ mkdir /mnt/nfs1
$ mount -t nfs nfs-server-hostname:/mnt/nfsshare /mnt/
$ mount  | grep nfs1
fs-server-hostname:/mnt/nfsshare on /mnt/nfs1 type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.10.10.2,local_lock=none,addr=10.10.10.1)