NFS(Network File System) is a distributed file system protocol that allows a user on a client computer to access files over a computer network much like local storage is accessed. It is a popular, cross-platform and distributed file system protocol used to export local file systems over the network so that clients can share directories and files with others over a network and interact with them as though they are mounted locally. This distributed file system protocol allows a user on a client computer to access files over a network in the same way they would access a local storage file. Because it is an open standard, anyone can implement the protocol.
Rocky Linux 8 supports NFS version 3(NFSv3) and 4(NFSv4). The default NFS version is 4.2 which features support for Access Control Lists (ACLs), server-side copy, sparse files, space reservation, labeled NFS, layout enhancements, and much more.
In this guide, we will learn how to install and configure the NFS Server and NFS client on Rocky Linux 8.
Prerequisites
- Updated Rocky Linux Server to be used as the server and another one for the client
- Connectivity from the servers
- Sudo access from the servers
Ensuring that the server is up to date
Before proceeding, let us ensure that the server is up to date. Use this command to achieve this:
|
|
Install the NFS packages
The package nfs-utils
provides a daemon for the kernel NFS server and related tools such as the contains the showmount
program. Use this command to install the package:
|
|
Starting and enabling the NFS server
Once the NFS packages is installed successfully, we can start and enable the NFS server. Use this systemctl command to start the server:
|
|
Confirm the status of the service with this command:
|
|
The above output shows that the service was started successfully. To enable the service to start at system boot, use this command:
|
|
Please note that the other services that are required for running an NFS server or mounting NFS shares such as nfsd
, nfs-idmapd
, rpcbind
, rpc.mountd
, lockd
, rpc.statd
, rpc.rquotad
and rpc.idmapd
will be started automatically.
Enabling the NFS Service in Firewall
If you have firewalld installed and enabled, you need to enable the NFS services. You need to allow traffic to the necessary NFS services (mountd
, nfs
, rpc-bind
) via the firewall, then reload the firewall rules to apply the changes, as follows.
|
|
Configuring exports on NFS server
The configuration files for NFS server are located in these paths:
/etc/nfs.conf
- this is the main configuration file for the NFS daemons and tools/etc/nfsmount.conf
- this is the NFS mount configuration file
Let us create file systems to export or share on the NFS server. We will create two file systems to stare, /mnt/nfs_shares/files
for shared files and /mnt/nfs_shares/backup
for backups.
Let us create the directories in the server
|
|
Confirm
|
|
Then add the above filesystems in the exports file /etc/exports
in the NFS server to determine the local file systems that are exported to the NFS clients.
Open the exports file with your text editor
|
|
Then add this content:
|
|
These are the export options that can be used:
rw
- allows both read and write access on the file system.sync
- tells the NFS server to write operations (writing information to the disk) when requested (applies by default).all_squash
- maps all UIDs and GIDs from client requests to the anonymous user.no_all_squash
- used to map all UIDs and GIDs from client requests to identical UIDs and GIDs on the NFS server.root_squash
- maps requests from root user or UID/GID 0 from the client to the anonymous UID/GID.
Once the file systems are defined in the exports file, we need to run the exportfs
command for them to be exported. The exportfs can be run with the -a
flag meaning export or unexport all directories, -r
meaning reexport all directories, synchronizing /var/lib/nfs/etab
with /etc/exports
and files under /etc/exports.d
, and -v
enables verbose output.
|
|
This is the output on my server
|
|
To display the current export list, run the following command. Please note that the exportfs table also applies some default options that are not explicitly defined:
|
|
Setting up NFS Client systems
Now that we have configured the exports on the server, we can access them from the client system. Login to the client system and install the necessary packages to allow NFS shares to be accessed.
On RHEL based systems:
|
|
On Debian/Ubuntu based distros:
|
|
We can then run the showmount command to show mount information for the NFS Server. The command outputs exported filesystems on the server
|
|
Output
|
|
Create a local file system directory for mounting the remote NFS file systems and mount it as an nfs file system
|
|
We can then confirm that the remote file system has been mounted by running the mount
command and filter nfs
mounts.
|
|
Output on my machine
|
|
To enable the mount to persistent even after a system reboot, add the entries to the /etc/fstab
file. Use these commands(as root) to achieve that:
|
|
Lastly, test if NFS
setup is working fine by creating a file on the server and check if the file can be seen in the client.
On the server:
|
|
Then on the client machine confirm
|
|
You can also do the reverse. On the client:
|
|
Then on the server confirm:
|
|
To unmount the remote file system on the client-side.
|
|
Please note that you can not unmount
the remote file system if you are operating within it.
Conclusion
In this guide we managed to install and configure an NFS server and client on Rocky Linux 8.