How to Install and Configure NFS on Red Hat Enterprise Linux 9

How to Install and Configure NFS on Red Hat Enterprise Linux 9

NFS stands for Network File System. It is a network protocol for distributed file systems. Using NFS, a user on the client computer can access the shared folder on server as if it is accessing locally.

In this tutorial, we will see how we can set up an NFS server on Red Hat Enterprise Linux 9 and share a folder on the server machine and access it from client computer.

Prerequisites

  • Two RHEL 9 instances (Client and Server)
  • Root account or an account with sudo privileges
  • Both Client and Server machines are on the same network
  • Stop the firewall on both sides (systemctl stop firewalld)

Install NFS Packages on Red Hat Enterprise Linux 9 Server Machine

Open up the terminal and install the following packages on Red Hat Linux 9 server machine.

  • nfs-utils
  • libnfsidmap
yum install nfs-utils libnfsidmap

Start the NFS Services

Start the following NFS services:

  • rpcbind
  • nfs-server
  • rpc-statd
  • nfs-idmapd

Run the command on terminal:

systemctl start rpcbind.service nfs-server.service rpc-statd.service nfs-idmapd.service

Verifying by checking the status of all these services and make sure they are up and running.

Run the command.

systemctl status rpcbind.service nfs-server.service rpc-statd.service nfs-idmapd.service

Create a Directory

Create a directory you want to share with client machine. We will create a new directory called apps in the location /server/.

mkdir /server
cd /server
mkdir apps

In our case they are already created as you can see from the screenshot.

If you execute a command pwd, you will get the following path

/server/apps

Assign permissions to new directory

Assign all permissions to new directories /server and /server/apps.

Run the commands:

chmod 777 /server
chmod 777 /server/apps

Modify the file located at /etc/exports and add a rule.

<Path of shared folder> <IP_allow> (rw,sync,no_root_squash)

In our case the complete line will be following. * shows the folder is shared with all machines on the network. You can put an IP address of machine to share with single machine on the network.

/server/apps * (rw,sync,no_root_squash)
nano /etc/exports

Load the new changes make to the file with the help of command.

exportfs -rv

Install NFS packages on Red Hat Enterprise Linux 9 Client machine

Open up the terminal and install the following packages on client machine.

  • nfs-utils
  • rpcbind
yum install nfs-utils rpcbind

After installing the packages, start the rpcbind service on your system.

systemctl start rpcbind

You can verify the status of rpcbind service by using:

systemctl status rpcbind

Show mount from NFS server

Let’s check the mount or shared directory we have created on the server side. The syntax of the command is as follows:

showmount -e <IP of server side>

In our case the IP of server is 192.168.245.128 so our complete command would be:

showmount -e 192.168.245.128

Create a mount point

Create a folder on client side to link it to a shared folder on server side.

cd /
mdkir mnt
cd mnt

mkdir apps

cd apps
pwd

Mount the file system

The syntax of the command is as follows:

mount <IP_server>:/server/apps /mnt/apps

The complete command would be following. It will attach or link the shared directory on server /server/apps to the /mnt/apps/ with client machine.

mount 192.168.245.128:/server/apps /mnt/apps

To verify that the folder or directory has been mounted or not, execute the following and it should show you the mount point.

df -h

Conclusion

We have successfully mounted the shared folder from server side with client machine. Whatever you put in the directory /server/apps it will be synced with a folder /mnt/apps on client side and vice versa. If you have any problem, you can send us a comment and we will help you out.