RHEL 9 provides two mechanisms for sharing files and folders with other systems on a network. One approach is to use a technology called Samba. Samba is based on Microsoft Windows Folder Sharing and allows Linux systems to make folders accessible to Windows systems and access Windows-based folder shares from Linux. This approach can also be used to share folders between other Linux and UNIX-based systems as long as they have Samba support installed and configured. This is the most popular approach to sharing folders in heterogeneous network environments. Folder sharing using Samba is covered in Configuring Samba on RHEL 9.
Another option, explicitly targeted at sharing folders between Linux and UNIX-based systems, uses Network File System (NFS). NFS allows the file system on one Linux computer to be accessed over a network connection by another Linux or UNIX system. NFS was originally developed by Sun Microsystems (now part of Oracle Corporation) in the 1980s and remains the standard mechanism for sharing remote Linux/UNIX file systems.
NFS is very different from the Windows SMB resource-sharing technology used by Samba. This chapter will look at the network-based sharing of folders between RHEL 9 and other UNIX/ Linux-based systems using NFS.
Ensuring NFS Services are running on RHEL 9
The first task is to verify that the NFS services are installed and running on your RHEL 9 system. This can be achieved from the command line or the Cockpit interface.
Behind the scenes, NFS makes use of Remote Procedure Calls (RPC) to share filesystems over a network between different computers in the form of the rpcbind service. Begin by installing both rpcbind and the NFS service by running the following command from a terminal window:
# dnf install rpcbind nfs-utils
Next, configure these services so that they automatically start at boot time :
# systemctl enable rpcbind # systemctl enable nfs-server
Once the services have been enabled, start them as follows:
# systemctl start rpcbind # systemctl start nfs-server
Configuring the RHEL 9 Firewall to Allow NFS Traffic
Next, the firewall needs to be configured to allow NFS traffic. To achieve this, run the following firewall-cmd commands where <zone> is replaced by the appropriate zone for your firewall and system configuration:
# firewall-cmd --zone=<zone> --permanent --add-service=mountd # firewall-cmd --zone=<zone> --permanent --add-service=nfs # firewall-cmd --zone=<zone> --permanent --add-service=rpc-bind # firewall-cmd --reload
Specifying the Folders to be Shared
Now that NFS is running and the firewall has been configured, we need to specify which parts of the RHEL 9 file system may be accessed by remote Linux or UNIX systems. These settings can be declared in the /etc/exports file, which must be modified to export the directories for remote access via NFS. The syntax for an export line in this file is as follows:
<export> <host1>(<options>) <host2>(<options>)...
In the above line, <export> is replaced by the directory to be exported, <host1> is the name or IP address of the system to which access is being granted, and <options> represents the restrictions that are to be imposed on that access (read-only, read-write, etc.). Multiple host and options entries may be placed on the same line if required. For example, the following line grants readonly permission to the /datafiles directory to a host with the IP address 192.168.2.38:
The use of wildcards is permitted to apply an export to multiple hosts. For example, the following line permits read-write access to /home/demo to all external hosts:
A complete list of options supported by the exports file may be found by reading the exports man page:
# man exports
For this chapter, we will configure the /etc/exports file as follows:
/tmp *(rw,sync) /vol1 192.168.86.42(ro,sync)
Once configured, the table of exported file systems maintained by the NFS server needs to be updated with the latest /etc/exports settings using the exportfs command as follows:
# exportfs -a
It is also possible to view the current share settings from the command line using the exportfs tool:
The above command will generate the following output:
/vol1 192.168.86.42 /tmp <world>
Accessing Shared Folders
The shared folders may be accessed from a client system by mounting them manually from the command line. However, before attempting to mount a remote NFS folder, the nfs-utils package must first be installed on the client system:
# dnf install nfs-utils
To mount a remote folder from the command line, open a terminal window and create a directory where you would like the remote shared folder to be mounted:
$ mkdir /home/demo/tmp
Next, enter the command to mount the remote folder using either the IP address or hostname of the remote NFS server, for example:
$ sudo mount -t nfs 192.168.86.24:/tmp /home/demo/tmp
The remote /tmp folder will then be mounted on the local system. Once mounted, the /home/ demo/tmp folder will contain the remote folder and all its contents.
Options may also be specified when mounting a remote NFS filesystem. The following command, for example, mounts the same folder but configures it to be read-only:
$ sudo mount -t nfs -o ro 192.168.86.24:/tmp /home/demo/tmp
Mounting an NFS Filesystem on System Startup
It is also possible to configure a RHEL 9 system to automatically mount a remote file system each time it starts up by editing the /etc/fstab file. When loaded into an editor, it will likely resemble the following:
/dev/mapper/rhel-root / xfs defaults 0 0 UUID=c4ba0b0f-777a-42a8 /boot xfs defaults 0 0 UUID=052D-19D8 /boot/efi vfat umask=0077,shortname=winnt 0 2 /dev/mapper/rhel-swap none swap defaults 0 0
To mount, for example, a folder with the path /tmp, which resides on a system with the IP address 192.168.1.115 in the local folder with the path /home/demo/tmp (note that this folder must already exist) add the following line to the /etc/fstab file:
192.168.86.24:/tmp /home/demo/tmp nfs rw 0 0
Next time the system reboots, the /tmp folder on the remote system will be mounted on the local /home/demo/tmp mount point. All the files in the remote folder can then be accessed as if they reside on the local hard disk drive.
Unmounting an NFS Mount Point
Once a remote file system is mounted using NFS, it can be unmounted using the umount command with the local mount point as the command-line argument. The following command, for example, will unmount our example filesystem mount point:
$ sudo umount /home/demo/tmp
Accessing NFS Filesystems in Cockpit
In addition to mounting a remote NFS file system on a client using the command line, it is also possible to perform mount operations from within the Cockpit web interface. Assuming that Cockpit has been installed and configured on the client system, log into the Cockpit interface from within a web browser and select the Storage option from the left-hand navigation panel. If the Storage option is not listed, the cockpit-storaged package will need to be installed:
# dnf install cockpit-storaged # systemctl restart cockpit.socket
Once the Cockpit service has restarted, log back into the Cockpit interface, at which point the Storage option should now be visible.
Once selected, the main storage page will include a section listing any currently mounted NFS file systems, as illustrated in Figure 19-1:
To mount a remote filesystem, click on the ‘+’ button highlighted above and enter information about the remote NFS server and file system share together with the local mount point and any necessary options into the resulting dialog before clicking on the Add button:
To modify, unmount or remove an NFS filesystem share, select the corresponding mount in the NFS Mounts list (Figure 19-1 above) to display the page shown in Figure 19-3 below:
Within this screen, perform tasks such as changing the server or mount points or unmounting the file system. For example, the Remove option unmounts the file system and deletes the entry from the /etc/fstab file so that it does not re-mount the next time the system reboots.
The Network File System (NFS) is a client/server-based system, originally developed by Sun Microsystems, which provides a way for Linux and Unix systems to share filesystems over a network. NFS allows a client system to access and (subject to permissions) modify files located on a remote server as though those files are stored on a local filesystem. This chapter has provided an overview of NFS and outlined the options for configuring client and server systems using the command line or the Cockpit web interface.