Changes

Jump to: navigation, search

Using NFS to Share RHEL Files with Remote Systems

10,757 bytes added, 18:55, 10 June 2019
Created page with "{{#pagetitle: Using NFS to Share RHEL 8 Files with Remote Systems }} <table border="0" cellspacing="0" width="100%"><tr> <td width="20%">Displaying RHEL Applications Remotel..."
{{#pagetitle: Using NFS to Share RHEL 8 Files with Remote Systems }}
<table border="0" cellspacing="0" width="100%"><tr>
<td width="20%">[[Displaying RHEL Applications Remotely (X11 Forwarding)|Previous]]<td align="center">[[Red Hat Enterprise Linux Essentials|Table of Contents]]<td width="20%" align="right">[[Sharing Files between RHEL and Windows Systems with Samba|Next]]</td>
<tr>
<td width="20%">Displaying RHEL 8 Applications Remotely (X11 Forwarding)<td align="center"><td width="20%" align="right">Sharing Files between RHEL 8 and Windows Systems with Samba</td>
</table>
<hr>


<htmlet>rhel8</htmlet>


RHEL 8 provides two mechanisms for sharing files and folders with other systems on a network. One approach is to use technology called Samba. Samba is based on Microsoft Windows Folder Sharing and allows Linux systems to make folders accessible to Windows systems, and also to 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 too have Samba support installed and configured. This is by far the most popular approach to sharing folders in heterogeneous network environments. The topic of folder sharing using Samba is covered in [[Sharing Files between RHEL and Windows Systems with Samba|Sharing Files between RHEL 8 and Windows Systems with Samba]].

Another option, which is targeted specifically at sharing folders between Linux and UNIX based systems, uses technology called 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 of remote Linux/UNIX file systems to this day.

NFS is very different to the Windows SMB resource sharing technology used by Samba. In this chapter we will be looking at network based sharing of folders between RHEL 8 and other UNIX/Linux based systems using NFS.

== Ensuring NFS Services are running on RHEL 8 ==

The first task is to verify that the NFS services are installed and running on your RHEL 8 system. This can be achieved either from the command-line, or using the Cockpit interface.

Behind the scenes, NFS makes use of ''rpcbind'' service. Begin by installing both rpcbind and the NFS service by running the following command from a terminal window:

<pre>
# dnf install rpcbind nfs-utils
</pre>

Next, configure these services so that they automatically start at boot time:

<pre>
# systemctl enable rpcbind
# systemctl enable nfs-server
</pre>

Once the services have been enabled, start them as follows:

<pre>
# systemctl start rpcbind
# systemctl start nfs-server
</pre>

== Configuring the RHEL 8 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 &lt;zone&gt; is replaced by the appropriate zone for your firewall and system configuration:

<pre>
firewall-cmd --zone=''&lt;zone&gt;'' --permanent --add-service=mountd
firewall-cmd --zone=''&lt;zone&gt;'' --permanent --add-service=nfs
firewall-cmd --zone=''&lt;zone&gt;'' --permanent --add-service=rpc-bind
firewall-cmd --reload
</pre>

== Specifying the Folders to be Shared ==

Now that ''/etc/exports ''file, which will need to be modified to export the directories for remote access via NFS. The syntax for an export line in this file is as follows:

<pre>
&lt;export&gt; &lt;host1&gt;(&lt;options&gt;) &lt;host2&gt;(&lt;options&gt;)...
</pre>

In the above line, &lt;export&gt; is replaced by the directory to be exported, &lt;host1&gt; is the name or IP address of the system to which access is being granted and &lt;options&gt; 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 read only permission to the ''/datafiles'' directory to a host with the IP address of 192.168.2.38:

<pre>
/datafiles 192.168.2.38(ro)
</pre>

The use of wildcards is permitted in order to apply an export to multiple hosts. For example, the following line permits read write access to ''/home/demo'' to all external hosts:

<pre>
/home/demo *(rw)
</pre>

A full list of options supported by the exports file may be found by reading the exports man page:

<pre>
# man exports
</pre>

For the purposes of this chapter, we will configure the ''/etc/exports'' file as follows:

<pre>
/tmp *(rw,sync)
/vol1 192.168.2.21(ro,sync)
</pre>

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:

<pre>
# exportfs -a
</pre>

It is also possible to view the current share settings from the command-line using the ''exportfs'' tool:

<pre>
# exportfs
</pre>

The above command will generate the following output:

<pre>
/tmp &lt;world&gt;
/vol1 192.168.2.21
</pre>

== Accessing Shared RHEL 8 Folders ==

The shared folders may be accessed from a client system by mounting them manually from the command-line. Before attempting to mount a remote NFS folder, the ''nfs-utils'' package should first be installed on the client system:

<pre>
# dnf install nfs-utils
</pre>

To mount a remote folder from the command-line, open a terminal window and create a folder where you would like the remote folder to be mounted:

<pre>
mkdir /home/demo/tmp
</pre>

Next enter the command to mount the remote folder using either the IP address or hostname of the remote NFS server, for example:

<pre>
# mount -t nfs 192.168.1.115:/tmp /home/demo/tmp
</pre>

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:

<pre>
# mount -t nfs -o ro 192.168.1.115:/tmp /home/demo/tmp
</pre>

== Mounting an NFS Filesystem on System Startup ==

It is also possible to configure a RHEL 8 system to automatically mount a remote file system each time the system starts up by editing the ''/etc/fstab'' file. When loaded into an editor, it will likely resemble the following:

<pre>
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=c2c3b49a-e1a1-4004 /boot xfs defaults 0 0
/dev/mapper/rhel-home /home xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
</pre>

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:

<pre>
192.168.1.115:/tmp /home/demo/tmp nfs rw 0 0
</pre>

Next time the system reboots the ''/tmp'' folder located 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:

<pre>
# umount /home/demo/tmp
</pre>

== 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 and the cockpit service restarted as follows:

<pre>
# dnf install cockpit-storaged
# systemctl restart cockpit.socket
</pre>

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 17-1:


[[File:rhel_8_cockpit_nfs_mounts.png]]


Figure 17-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:


[[File:rhel_8_cockpit_nfs_mount_dialog.png]]


Figure 17-2


To modify, unmount or remove an NFS filesystem share, select the corresponding mount in the NFS Mounts list (Figure 17-1 above) to display the page shown in Figure 17-3 below:


[[File:rhel_8_cockpit_nfs_mount_modify.png]]


Figure 17-3

Within this screen perform tasks such as changing the server or mount points or unmounting the file system. The Remove option unmounts the file system and deletes the entry from the ''/etc/fstab'' file so that it does not re-mount next time the system reboots.

== Summary ==

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 available for configuring both client and server systems using the command-line or the Cockpit web interface.


<htmlet>rhel8</htmlet>


<hr>
<table border="0" cellspacing="0" width="100%"><tr>
<td width="20%">[[Displaying RHEL Applications Remotely (X11 Forwarding)|Previous]]<td align="center">[[Red Hat Enterprise Linux Essentials|Table of Contents]]<td width="20%" align="right">[[Sharing Files between RHEL and Windows Systems with Samba|Next]]</td>
<tr>
<td width="20%">Displaying RHEL 8 Applications Remotely (X11 Forwarding)<td align="center"><td width="20%" align="right">Sharing Files between RHEL 8 and Windows Systems with Samba</td>
</table>

Navigation menu