The full form of NFS is Network File System. It is a distributed file system protocol. NFS allows you to share a directory from your NFS server over the network which can be mounted from one or multiple NFS clients and be accessed simultaneously.

In this article, I am going to show you how to configure NFS server and clients on CentOS 8. So, let’s get started.

Network Topology:

How to Configure NFS Server on CentOS 8 centos nfs

Figure 1: Network topology used in this article

In this article, 3 CentOS 8 machines are used. They are connected as in figure 1.

nfs-server will be configured as an NFS file server.

nfs-client1 and nfs-client2 will be configured as NFS client. They will mount the shared filesystem path from the NFS server nfs-server.

nfs-server network configuration:

IP address: 192.168.20.178/24

nfs-client1 network configuration:

IP address: 192.168.20.176/24

nfs-client2 network configuration:

IP address: 192.168.20.177/24

Configuring the Server:

First, you have to set up a static IP address on the nfs-server CentOS 8 machine. If you need any help on that, check the article Configuring Static IP on CentOS 8.

Now, SSH into your nfs-server machine.

$ ssh shovon@192.168.20.178

How to Configure NFS Server on CentOS 8 centos nfs

Update the DNF package repository cache with the following command:

How to Configure NFS Server on CentOS 8 centos nfs

Install the nfs-utils package with the following command:

$ sudo dnf install nfs-utils

How to Configure NFS Server on CentOS 8 centos nfs

To confirm the installation, press Y and then press .

How to Configure NFS Server on CentOS 8 centos nfs

nfs-utils package should be installed.

How to Configure NFS Server on CentOS 8 centos nfs

Now, add the nfs-server and rpcbind services to the system startup with the following command:

$ sudo systemctl enable nfs-server rpcbind

How to Configure NFS Server on CentOS 8 centos nfs

Now, start the nfs-server and rpcbind services with the following command:

$ sudo systemctl start nfs-server rpcbind

How to Configure NFS Server on CentOS 8 centos nfs

The nfs-server and rpcbind services should be active (running).

$ sudo systemctl status nfs-server rpcbind

How to Configure NFS Server on CentOS 8 centos nfs

Now, you can share any directory path on your server using NFS.

In this article, I am going to show you how to make partitions, format the partition, mount them to specific directory path and share it using NFS. If the directory path you want to share is ready, you can skip ahead.

First, find the storage device name using the following command:

In my case, the name of the SSD I will use is nvme0n2. It will be different for you. So, make sure to replace it with yours from now on.

How to Configure NFS Server on CentOS 8 centos nfs

Now, run cfdisk as follows:

$ sudo cfdisk /dev/nvme0n2

How to Configure NFS Server on CentOS 8 centos nfs

If you don’t have a partition table already, cfdisk will show you this window. Select gpt and press .

How to Configure NFS Server on CentOS 8 centos nfs

Now, select the Free space, navigate to [ New ] and press .

How to Configure NFS Server on CentOS 8 centos nfs

Type in the partition size and press .

NOTE: Use M for MiB, G for GiB and T for TiB disk size unit.

How to Configure NFS Server on CentOS 8 centos nfs

A new partition /dev/nvme0n2p1 should be created. Now, select [ Write ] and press .

How to Configure NFS Server on CentOS 8 centos nfs

Now, type in yes and press .

How to Configure NFS Server on CentOS 8 centos nfs

The changes should be written to the partition table.

How to Configure NFS Server on CentOS 8 centos nfs

Now, select [ Quit ] and press .

How to Configure NFS Server on CentOS 8 centos nfs

As you can see, a new partition nvme0n2p1 is created.

How to Configure NFS Server on CentOS 8 centos nfs

Now, create a filesystem on the nvme0n2p1 partition with the following command:

$ sudo mkfs.ext4 -L nfs-share /dev/nvme0n2p1

How to Configure NFS Server on CentOS 8 centos nfs

Now, make a directory (in my case /nfs-share) where you want to mount the newly created partition with the following command:

How to Configure NFS Server on CentOS 8 centos nfs

Now, to automatically mount the partition when your nfs-server boots, you have to add an entry to the /etc/fstab file.

To edit the /etc/fstab file, run one of the following commands:

OR

How to Configure NFS Server on CentOS 8 centos nfs

Now, add the following line to the file and save the file.

/dev/nvme0n2p1    /nfs-share    ext4    defaults    0    0

How to Configure NFS Server on CentOS 8 centos nfs

Now, you can easily mount the newly created partition to the /nfs-share directory as follows:

How to Configure NFS Server on CentOS 8 centos nfs

As you can see, the partition is mounted to the /nfs-share directory.

How to Configure NFS Server on CentOS 8 centos nfs

Now, to share the /nfs-share directory with NFS, edit the /etc/exports configuration file with one of the following commands:

OR

How to Configure NFS Server on CentOS 8 centos nfs

Now, you have to add the following line to the /etc/exports file.

/nfs-share    192.168.20.0/24(rw,no_root_squash)

How to Configure NFS Server on CentOS 8 centos nfs

The format of the line is:

share_directory_path  host1(host1_options) host2(host2_options_)

In this article, the share_directory_path is /nfs-share

After specifying the share directory, you can add one or more hosts and access options for each host.

Here, the host is 192.168.20.0/24. So, everyone on the subnet, 192.168.20.1 to 192.168.20.254 will be able to access this share.

The options are rw and no_root_squash.

Here,

rw – allows read and write to the share

no_root_squash – does not allow NFS server to map any user or group id to anonymous user or group id.

There are many more options which you can use. To learn more about it, check the manpage of exports.

How to Configure NFS Server on CentOS 8 centos nfs

Now, to enable the share without restarting the server, run the following command:

How to Configure NFS Server on CentOS 8 centos nfs

If you have SELinux enabled, run the following command:

$ sudo setsebool -P nfs_export_all_rw 1

How to Configure NFS Server on CentOS 8 centos nfs

Now, to allow access to the NFS ports from the NFS clients, configure the firewall with the following command:

$ sudo firewall-cmd –add-service={nfs,nfs3,mountd,rpc-bind} –permanent

How to Configure NFS Server on CentOS 8 centos nfs

Now, for the firewall changes to take effect, run the following command:

$ sudo firewall-cmd –reload

How to Configure NFS Server on CentOS 8 centos nfs

Configuring the Client:

Now, to mount the NFS share /nfs-share from the nfs-server to nfs-client1 machine, you need to install the nfs-utils package on nfs-client1 machine as well.

First, update the DNF package repository cache as follows:

How to Configure NFS Server on CentOS 8 centos nfs

Now, install the nfs-utils package as follows:

$ sudo dnf install nfs-utils

How to Configure NFS Server on CentOS 8 centos nfs

Now, press Y and then press .

How to Configure NFS Server on CentOS 8 centos nfs

nfs-utils should be installed.

How to Configure NFS Server on CentOS 8 centos nfs

Now, to confirm whether the NFS share is accessible from the client machine, run the following command:

$ sudo showmount –exports 192.168.20.178

Here, 192.168.20.178 is the IP address of nfs-server machine.

As you can see, /nfs-share is accessible from the nfs-client1 machine.

How to Configure NFS Server on CentOS 8 centos nfs

Now, make a mount point for the NFS share as follows:

$ sudo mkdir /mnt/nfs-share

How to Configure NFS Server on CentOS 8 centos nfs

Now, you can mount the NFS share /nfs-share from the nfs-server machine to the /mnt/nfs-share directory of the nfs-client1 machine with the following command:

$ sudo mount -t nfs 192.168.20.178:/nfs-share /mnt/nfs-share

How to Configure NFS Server on CentOS 8 centos nfs

The NFS share should be mounted.

How to Configure NFS Server on CentOS 8 centos nfs

If you want to mount the NFS share when your nfs-client1 machine boots, you have to add an entry to the /etc/fstab file.

Edit the /etc/fstab file with one of the following commands:

OR

How to Configure NFS Server on CentOS 8 centos nfs

Now, add the following line to the file.

192.168.20.178:/nfs-share /mnt/nfs-share  nfs    defaults 0 0

How to Configure NFS Server on CentOS 8 centos nfs

nfs has a lot of mount options. I’ve used the defaults mount option here. But, if you have specific requirements, you may check the manpage of nfs.

How to Configure NFS Server on CentOS 8 centos nfs

Now, let’s create a new file hello.txt to the NFS share from the nfs-client1 machine.

$ echo “Hello NFS share” | sudo tee /mnt/nfs-share/hello.txt

How to Configure NFS Server on CentOS 8 centos nfs How to Configure NFS Server on CentOS 8 centos nfs

As you can see, the file hello.txt is also created in the nfs-server.

How to Configure NFS Server on CentOS 8 centos nfs

The contents of the hello.txt file read from the nfs-server machine.

How to Configure NFS Server on CentOS 8 centos nfs

The same way you can configure nfs-client2 and access the NFS share from there.

Install nfs-utils package on nfs-client2.

$ sudo dnf install nfs-utils

How to Configure NFS Server on CentOS 8 centos nfs

Edit /etc/fstab file.

OR

How to Configure NFS Server on CentOS 8 centos nfs

Add the following line to it.

192.168.20.178:/nfs-share  /mnt/nfs-share    nfs    defaults 0 0

How to Configure NFS Server on CentOS 8 centos nfs

Create a mount point.

$ sudo mkdir /mnt/nfs-share

How to Configure NFS Server on CentOS 8 centos nfs

Mount the share.

$ sudo mount /mnt/nfs-share

How to Configure NFS Server on CentOS 8 centos nfs

Access the files from the share. Very simple.

$ sudo cat /mnt/nfs-share/hello.txt

How to Configure NFS Server on CentOS 8 centos nfs

This is how you configure NFS server and client on CentOS 8. Thanks for reading this article.

About the author

How to Configure NFS Server on CentOS 8 centos nfs

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.