How to Install NFS Server and Client on RHEL-based Distributions

In Linux, there are a couple of file-sharing protocols used to share storage and files across a network. The most widely used ones are Samba and NFS.

Samba is a popular open-source application suite that works in a client-server architecture. It offers cross-platform compatibility enabling seamless file sharing across Linux, Windows, and macOS operating systems. A file share hosted on a Linux system can be accessed from diverse platforms, thus fostering collaboration.

Another widely used file-sharing protocol is NFS, short for Network File Share. Just like Samba, it works on a client-server model and allows a user to share directories and files across a network with multiple remote client users.

In this guide, we will check out how to install the NFS server and client on RHEL-based distributions such as Fedora, CentOS Stream, Rocky Linux, and AlmaLinux.

NFS Services

Currently, there are 3 versions of NFS, the latest one being NFSv4 which includes features such as the ability to work over the internet and across a firewall. In addition, there is NFSv3 and NFSv2 which is the oldest protocol.

The NFS service is made up of the NFS Server and client. The NFS server comprises the following key files:

  • nfs-server – This allows client systems to access the NFS-shared files.
  • rpcbind – converts RPC programs to universal addresses.
  • nfs-idmap – Carries out the translation of the user and group IDs to names and user and group names into IDs.
  • portmap – This is a server that converts RPC program numbers to IP port numbers.
  • nfslock – In case of an NFS server crash, the nfslock starts the required RPC processes.

NFS Configuration Services

Here are some of the key configuration files for NFS:

  • /etc/exports – The main configuration file, which stipulates the filesystems or directories to be exported and accessed by remote users.
  • /etc/fstab – This is a file that contains entries of mounted partitions. In NFS, the file contains entries of NFS share directories or filesystems which are permanently mounted and can persist a reboot.
  • /etc/sysconfig/nfs – It defines the ports needed during the running of RPC services.

NFS Server and Client Setup

To set up NFS shares, we’ll need at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

  • NFS ServerRHEL 9 with IP 10.128.15.213
  • NFS ClientRHEL 9 with IP 10.128.15.214

Install NFS on Server and Client

To start off, you need to log into both nodes (NFS server and client) and install the NFS services. First, update the package information as shown. The following dnf command will also upgrade all the exciting packages to their latest versions.

$ sudo dnf update 

Once the update is complete, proceed and install the requisite NFS services.

$ sudo dnf install rpcbind nfs-utils -y
Install NFS in Linux
Install NFS in Linux

The next step is to enable the NFS services as shown.

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

Be sure to also start the NFS services.

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

It’s crucial to verify that all the NFS services are running.

$ sudo systemctl status nfs-server
$ sudo systemctl status rpcbind
Check NFS Status
Check NFS Status

Be sure to also configure the firewall in order to allow inbound NFS services as follows.

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

Create an NFS Share Directory

With all the NFS services installed and running as expected, it’s time to create the NFS share directory, which is the directory that will contain files that will be accessed by NFS clients in the network.

In this case, we will create an NFS share directory called my_nfsshare in our home directory.

$ mkdir -p /home/tecmint/my_nfsshare

Next, assign directory permissions. For demonstration purposes, we will assign global permissions that will accord NFS clients read, write, and execute permissions.

$ sudo chmod 777 -R /home/tecmint/my_nfsshare
Create NFS Share Directory
Create an NFS Share Directory

Export an NFS Share Directory

The next step is to export the NFS share directory. In order to achieve this, we need to make an entry in the /etc/exports file. Therefore, access the file using your preferred text editor. In this case, we will use the Vim editor.

$ sudo vim /etc/exports

Add the following entry. Be sure to replace the server-ip with your NFS server’s IP address.

/home/tecmint/my_nfsshare server-ip/24(rw,no_root_squash)

Finally export the NFS share directory or filesystem.

$ sudo exportfs -rv
Export NFS Share Directory
Export NFS Share Directory

Run the following command to view the NFS shares.

$ showmount -e localhost
View NFS Share Directory
View NFS Share Directory

Configure NFS Client

The remaining phase of this exercise is to configure the NFS client in order to access the shared directory. First, confirm that you can view the export list or NFS shares on the NFS server.

# showmount -e 10.128.15.213
List NFS Share Directory
List NFS Share Directory

The next step is to mount the NFS share from the server to the client. To do this, we first need to create a mount directory. In this case, we will create a directory called nfs_backup.

# mkdir nfs_backup

Thereafter, we will mount the NFS share to the mount directory that we have just created in the root home directory

# mount -t nfs 10.128.15.213:/home/tecmint/my_nfsshare  ~/nfs_backup 

To persist the NFS share, edit the /etc/fstab file.

# vim /etc/fstab

Then add the following entry.

10.128.15.213:/home/tecmint/my_nfsshare    /root/nfs_backup  nfs     defaults 0 0
Mount NFS Share Directory
Mount NFS Share Directory

Save and exit the configuration file.

Testing NFS Setup

The last step is to verify if the NFS setup is working as expected. We will create a few files on the server and verify their availability on the NFS client side.

On the server side, we will create the files in the NFS share directory.

$ sudo touch my_nfsshare/file{1..4}.txt

To verify that the files have been created, we will execute the ls command:

$ ls -l my_nfsshare/
Verify NFS Share Directory
Verify NFS Share Directory

Back to the client side, verify that the files are available in the mount directory without any service refresh or restart of any services as seen in the following output.

$ ls -l nfs_backup/
Check NFS Share Files
Check NFS Share Files

Removing NFS Mount

If you no longer need the mounted directory on your system, you can unmount them from the client side using the following umount command:

$ umount ~/nfs_backup

NFS Share Commands

Some more important commands for NFS.

  • showmount -e – Shows the available shares on your local machine
  • showmount -e ip-address – Lists the available shares at the remote server
  • showmount -d – Lists all the sub-directories
  • exportfs -v – Displays a list of shared files and options on a server
  • exportfs -a – Exports all shares listed in /etc/exports, or given name
  • exportfs -u – Unexports all shares listed in /etc/exports, or given name
  • exportfs -r – Refresh the server’s list after modifying /etc/exports
Conclusion

This wraps up our guide on how to install the NFS server and client on RedHat-based distributions. We have installed the NFS services on the server, created an NFS share directory, and finally mounted the share directory on the client. Lastly, we verified the NFS setup by accessing the file created on the server from the client side.

If you read this far, tweet to the author to show them you care. Tweet a thanks
James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

128 thoughts on “How to Install NFS Server and Client on RHEL-based Distributions”

  1. Found some missing files in the fedora 33 servers /etc the exports file has to be created, also I cruised thru usr/systemd.conf files, some needed a user added as only root can access some of them. Redhat has removed the “rsh” login while Debian has it, with rsh I can connect eth0 to the dell idrac port, type rsh 192.168.0.? And can log in gives tons of cli commands that the web-based idrac doesn’t seem to have, not sure there’s a difference in formats.

    Debian for some reason does not include netstat if config and FTP? Also, fedora7 and 8 had rwhod, whois, telnet, FTP, apache web server. The fefora33 server I’m using lacks these old tools and I’m not sure if I’m getting past the firewall other than pinging my idrac on my dell server!

    Unfortunately, I have to go online to ad nfs files to make it work in the fedora33 server. I noticed you used init.d but redhat and its subsidiary ones all use the system.d in their configuration, so init.d might not work on a redhat/fedora/centos box!

    Reply
  2. I have one doubt, why he did not add some services to the firewall without adding? it is possible.

    below are some of the services – nfs-server, rpcbind mounted,

    can some confirm

    Reply
  3. I had difficulty getting the server to reboot, the solution for me was to change the /etc/fstab on the nfsclient to the following:

    nfsserver:/var/nfsshare/work /opt/work nfs defaults,_netdev,x-systemd.after=nfs-server.service 0 0

    Reply
  4. This is one of the easiest installation. But this is not as simple as this is mentioned in the blog. Here the consideration is taken when the Firewall is stopped.

    Which specific ports to be allowed for NFS server to work properly. Only allowing NFS service is firewall is not working. It keeps on giving error of portmapper and something like that.

    I am doing it on CentOS 7, NFS server does not work independently so allowing NFS port is not making any difference

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.