How to: Configure NFS Server and Client on RHEL 7

Network File System (NFS) is a distributed file system protocol designed to share files over a computer network. A machine hosting the network drive is called server, where the machines that connect to access the drive are called clients.

NFS relies on Remote Procedure Calls (RPC) for remote communication. RPC services are controlled by the rpcbind service.

Two RHEL 7 servers are used in this tutorial, One acting as a server and another as a client.

Step 1: Downloading and Installing

Yum package manager is used to install nfs-utils package. “nfs-utils” includes all the needed services to build your NFS server.

$ sudo yum install -y nfs-utils

Step 2: Enable and Start NFS Server

Start the nfs-server and enable to make them bootable on the next reboot

$ sudo systemctl enable rpcbind
$ sudo systemctl start rpcbind
$ sudo systemctl enable nfs-server
$ sudo systemctl start nfs-server

Step 3: Export shared directory

Create a directory for NFS share to share with

$ mkdir /nfs_shared

Edit /etc/exports file

/nfs_shared client.example.com(rw,sync,no_root_squash,no_subtree_check)

where,

/nfs_share – shared directory
client1.example.com – Client address
rw – Writable permission to shared folder
sync – Synchronize shared directory
no_root_squash – Enable root privilege
no_all_squash - Enable user’s authority

The client info client.example.com can be specified in the following formats to control access to multiple clients.

192.168.1.2 - IP address of the client
192.168.1.1/16 - Subnet to specify supported client IP addresses

Run the following command to reflect changes in /etc/exports

exportfs -a

Step 4: Client

Similar to the server, using yum package manager is used to install nfs-utils package. “nfs-utils” includes necessary client packages to access the remote share.

$ sudo yum install -y nfs-utils

Verify if the client can access the share using “showmount” command

$ showmount -e server.example.comExport list for server.example.com
/nfs_share *
mount -t nfs server.example.com:/nfs_shared /nfs

Create a directory and mount the share

$ mkdir -p /mnt/dir1
$ mount -t nfs server.example.com:/nfs_share /mnt/dir1

Verify the mount using —

$ mount
# or
$ df -h

The directories mounted using “mount” command are not available upon reboots. To persist the mount points, the following entry should be saved to /etc/fstab file

/etc/fstab server.example.com:/nfs_shared /dir1 nfs rsize=8192,wsize=8192,timeo=14,intr

Unmount the share using umount /dir1

Cheers, now we have a successfully configured NFS Server and Client

--

--

All things Cloud-Native

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store