Linux has different types of storage that it offers. These are File storage, Object Storage, and Block Storage. File storage is the most common method of storing files in Linux. The files can be shared over a network and thus can be accessed by multiple users on a network. The files are transferred across protocols and can be formatted using NFS, SMB/CIFS, or AFB.

  • NFS which stands for Network File Server is used in Linux Operating Systems and is good for UNIX server-to-server file sharing.
  • SMB/CIFS which stands for Server Message Block/Common Internet File System is for the Microsoft Windows Operating system. It allows computers to read and write files to a remote host over a Local Area Network.
  • AFP which stands for Apple filling Protocol is a made for devices running the Mac Operating System.

NFS Server

The network file system allows you to mount files on a remote system over a network and interact with them as if they are mounted locally. Currently, there are 3 versions of NFS with NFSv4 being the latest that works through firewalls and on the internet. The NFSv3 has improved interoperability and performance. NFSv2 is the oldest and most commonly used on all platforms.

NFS service consists of the NFS server and NFS client. NFS client-server is used to share files and has services that are required for the process. These include

  • nfs-server which enables clients to access the NFS shared files.
  • rpcbind server that converts RPC programs to universal addresses.
  • portmap which you can take port reservations for local services.
  • nfslock that starts the appropriate RPC processes when the NFS server crashes.
  • nfs-idmap which translates user and group IDs to names and user and groups to names to IDs.

There are also configuration files that facilitate the NFS service. These include:

  • /etc/exports which is the main configuration file that controls which file systems are exported to remote systems.
  • /etc/fstab which controls what file systems are mounted when the system boots.
  • /etc/sysconfig/nfs which controls the ports required when RPC services are running.
  • /etc/hosts.allow and /etc/hosts.deny that control access to NFS server.

This guide will show you how to NFS server on CentOS 9|AlmaLinux 9| RHEL 9.

Install NFS Server on CentOS 9|AlmaLinux 9| RHEL 9

Update your system package.

sudo yum update

Install the NFS server using the following command

$ sudo yum -y install nfs-utils libnfsidmap
Installed:
  gssproxy-0.8.4-4.el9.x86_64            keyutils-1.6.1-4.el9.x86_64           
  libev-4.33-5.el9.x86_64                libnfsidmap-1:2.5.4-10.el9.x86_64     
  libverto-libev-0.3.2-3.el9.x86_64      nfs-utils-1:2.5.4-10.el9.x86_64       
  python3-pyyaml-5.4.1-6.el9.x86_64      rpcbind-1.2.6-2.el9.x86_64            
  sssd-nfs-idmap-2.7.0-2.el9.x86_64     

Complete!

Once installed, Enable and start the NFS services.

sudo systemctl enable --now rpcbind nfs-server
sudo systemctl start rpc-statd nfs-idmapd

Check the status of the NFS server with the following command.

$ systemctl status nfs-server
● nfs-server.service - NFS server and services
     Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendo>
     Active: active (exited) since Mon 2022-06-13 21:32:02 EAT; 46min ago
   Main PID: 6665 (code=exited, status=0/SUCCESS)
        CPU: 30ms

Jun 13 21:32:02 localhost.localdomain systemd[1]: Starting NFS server and servi>
Jun 13 21:32:02 localhost.localdomain systemd[1]: Finished NFS server and servi>

Configure NFS server on CentOS 9|AlmaLinux 9| RHEL 9

Create a directory to share with the clients.

sudo mkdir /nfs_shares

Change the directory permission to allow access.

sudo chmod 777 /nfs_shares/

Modify the configuration and add the following lines. Note the IP address is the one for the NFS client.

$ sudo nano /etc/exports
/nfs_shares *(rw,sync,no_root_squash)

Then run the following command to export the file system

sudo exportfs -rv

Use the following command to view the available NFS shares.

$ showmount -e localhost
Export list for localhost:
/nfs_shares 192.168.200.47

Allow the NFS services traffic through the firewall.

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

Mount NFS share on client machine

Install NFS service.

sudo yum -y install nfs-utils libnfsidmap

Start and enable the RPC services.

sudo systemctl start rpcbind
sudo systemctl enable rpcbind

Check the available NFS shares on the NFS server. The IP address is that of the NFS server.

$ showmount -e 192.168.200.70
Export list for 192.168.200.70:
/nfs_shares 192.168.200.47

Create a directory to mount the NFS files.

sudo mkdir nfs_backups

Mount the shared directory on the NFS server to the directory on the NFS Client.

sudo mount -t nfs 192.168.200.70:/nfs_shares ~/nfs_backups

To enable the mount to be persistent on a system reboot, edit the ftsab file.

$ sudo nano /etc/fstab
192.168.200.70:/nfs_shares     /nfs_backups  nfs     defaults 0 0

Save and exit the file.

Testing NFS service

Test if the NFS Service is working fine by creating a file on the NFS server and checking if it visible on the client-side

sudo touch /nfs_shares/file1.txt

To check on the client-side list it with the following command.

$ ls -l ~/nfs_backups/file1.txt
-rw-r--r--. 1 root root 0 Jun 13 22:52 /home/technixleo/nfs_backups/file1.txt

Create a file on the NFS client.

sudo touch ~/nfs_backups/file2.txt

Check if the file can be accessed on the NFS server.

$ ls -l /nfs_shares/file2.txt
-rw-r--r--. 1 root root 0 Jun 13 22:54 /nfs_shares/file2.txt

Conclusion

This guide has discussed the basics of NFS Server and the main services required to facilitate the process. We have also installed and configured NFS Server on CentOS 9|AlmaLinux 9| RHEL 9 systems. We have also configured an NFS client on a client system and tested the access of files on both the NFS server and the NFS client systems.

LEAVE A REPLY

Please enter your comment!
Please enter your name here