Install and Configure NFS Server on RHEL 8 / CentOS 8

Posted on 267 views

This guide will explain how to install NFS server on RHEL 8 / CentOS 8 Linux server. NFS stands for Network File System. It 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. NFS is a client-and-server file system(FS).

By using NFS shared storage, system administrators can consolidate resources onto centralized servers on the network. Files are easily shared between multiple systems on the same network. A client system can access the remote share with (read, write) privileges and do not have access to the underlying block storage.

For Ubuntu / Debian, check: Install and Configure NFS Server on Ubuntu & Debian Linux

Supported NFS versions

Below are the versions of NFS supported by RHEL 8.

NFS version 3 (NFSv3)

  • Has support for safe asynchronous writes and is more robust at error handling than the previous NFSv2
  • Supports 64-bit file sizes and offsets, allowing clients to access more than 2 GB of file data.

NFS version 4 (NFSv4)

  • Works through firewalls and on the Internet
  • No longer requires rpcbind service
  • Supports Access Control Lists (ACLs)
  • Utilizes stateful operations.

In this guide, we will setup NFSv4.2 on our RHEL/CentOS system. Here is my setup design.

Server Type OS IP Hostname
NFS Server RHEL/CentOS 8
NFS Client 1 RHEL/CentOS 8
NFS Client 2 RHEL/CentOS 8
Server Setup Table

But note that the configuration of NFS client will be covered in a separate guide. Follow the steps below to install NFS Server on CentOS 8 / RHEL 8 Linux system.

Step 1: Update server and set hostname

Your server should have a static IP address and static hostname that persists reboots. Check our guides on how to set static IP on RHEL/CentOS 8.

sudo yum -y update
sudo hostnamectl set-hostname --static

Step 2: Install NFS Server on CentOS 8 / RHEL 8

Next is the installation of the NFS server packages on RHEL / CentOS 8 system.

sudo yum -y install nfs-utils

After the installation, start and enable nfs-server service.

sudo systemctl enable --now nfs-server rpcbind

Status should show “running“.

setup-nfs-server-rhel-centos-8 (1)

Step 3: Exporting NFS Shares on RHEL 8 / CentOS 8

There are two ways to configure exports on an NFS server.

  1. Manually editing the /etc/exports configuration file
  2. Using the exportfs utility on the command line

The /etc/exports file controls which file systems are exported to remote hosts and specifies options. It follows the following syntax rules:

  • Blank lines are ignored.
  • To add a comment, start a line with the hash mark (#).
  • You can wrap long lines with a backslash (\).
  • Each exported file system should be on its own individual line.
  • Any lists of authorized hosts placed after an exported file system must be separated by space characters.
  • Options for each of the hosts must be placed in parentheses directly after the host identifier, without any spaces separating the host and the first parenthesis.

For this setup, I added a secondary disk to my server with a capacity of 20 GB. We will partition this disk and create file system on it for use as NFS share.

$ lsblk  | grep sdb
sdb             8:16   0   20G  0 disk 

# Create partition and file system
sudo parted -s -a optimal -- /dev/sdb mklabel gpt
sudo parted -s -a optimal -- /dev/sdb mkpart primary 0% 100%
sudo parted -s -- /dev/sdb align-check optimal 1
sudo mkfs.xfs /dev/sdb1

We’re going to mount it to /data directory.

sudo mkdir /data
echo "/dev/sdb1 /data xfs defaults 0 0" | sudo tee -a /etc/fstab
sudo mount -a

Let’s check the settings to confirm.

$ df -hT | grep /data
/dev/sdb1             xfs        20G  176M   20G   1% /data

I’ll create directory on /data/nfshare that will be exported to NFS clients.

sudo mkdir  /data/nfshare

Now we need to modify /etc/exports to configure NFS share. The structure is:

export host(options)

It is also possible to specify multiple hosts, along with specific options for each host, like below.

export host1(options1) host2(options2) host3(options3)


  • export is the directory being exported
  • host is the host or network to which the export is being shared
  • options List of options to be used for the host

In my setup, I’ll give the exported file system is read & write permissions to allow remote hosts to make changes to the data shared on the file system. My host will be a network

So my line on /etc/exports file will be.

/data/nfshare ,no_root_squash)

The no_root_squash option disables root squashing – enables remote root user to have root privileges. This is usually required for VM installations on NFS share.

To learn more about available options, use:

$ man exports

Once you’re done with the settings, use the exportfs utility to selectively export directories without restarting the NFS service.

$ sudo exportfs -rav
  • r – Causes all directories listed in /etc/exports to be exported by constructing a new export list in /etc/lib/nfs/xtab
  • a – All directories are exported or unexported, depending on what other options are passed to exportfs
  • v – Verbose operation – Show what’s going on

If Firewalld is running, allow NFS service.

sudo firewall-cmd --add-service=nfs --permanent
sudo firewall-cmd --add-service=nfs3,mountd,rpc-bind --permanent 
sudo firewall-cmd --reload 

SELinux boolean may need to be enabled.

sudo setsebool -P nfs_export_all_rw 1

Step 4: Mounting NFS Shares on Client Machines

Now that we’re done with NFS server configurations, the remaining part is mounting NFS shares on a client system. A client can be a remote system, a Virtual Machine on the same server or the server itself.

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.