Best Set Up NFS Server and Client on AlmaLinux 9
In this guide, we aim to provide a comprehensive walkthrough on how to Best Set Up NFS Server and Client on AlmaLinux 9. NFS (Network File System) is a distributed file system protocol that allows users on client computers to access files over a network in a manner similar to how local storage is accessed. This is especially useful in centralized environments where data needs to be stored and accessed from a single, central server. Follow the steps below to successfully set up your NFS server and client.
To effectively complete this guide on AlmaLinux NFS Server and AlmaLinux NFS Client configuration, you will need access to your server as a non-root user with sudo privileges. Furthermore, a basic firewall should be configured. You can refer to a guide like "Initial Server Setup with AlmaLinux 9" for this purpose.
You will also require a client machine. While any RHEL-based distribution can be used, this guide will specifically utilize AlmaLinux NFS Server and AlmaLinux NFS Client for demonstration purposes. Now let’s see how to Best Set Up NFS Server and Client on AlmaLinux 9.
Step 1 – Install NFS Server on AlmaLinux 9
First, update your system packages to their latest versions:
sudo dnf update -y
Next, install the NFS server packages:
sudo dnf install nfs-utils -y
Now, you need to configure the idmapd.conf
file. This file maps user and group IDs between the server and client. Open the file with a text editor (e.g., vi):
sudo vi /etc/idmapd.conf
Find the Domain
directive and uncomment it (remove the #
at the beginning of the line). Change the value to your server’s hostname or Fully Qualified Domain Name (FQDN):
Domain = almalinux-server
Save the changes and close the file.
Manage NFS Server Service
Start and enable the NFS server service using the following commands:
# sudo systemctl start nfs-server
# sudo systemctl enable nfs-server
Verify that the NFS server is active and running:
sudo systemctl status nfs-server
The output should resemble:

Step 2 – Create NFS Shared Directories on AlmaLinux 9
Now, create the directories that will be shared with NFS clients. In this example, we’ll create /mnt/shared
and /mnt/backup
:
sudo mkdir -p /mnt/shared /mnt/backup
Set the appropriate permissions and ownership for these directories:
# sudo chown -R nobody:nobody /mnt/shared /mnt/backup
# sudo chmod 775 /mnt/shared /mnt/backup
Next, configure the /etc/exports
file. This file specifies which directories are shared and which clients can access them.
sudo vi /etc/exports
Add the following lines to the file, customizing the IP addresses and options as needed:
/mnt/backup 192.168.10.21(rw,sync,no_subtree_check)
/home 192.168.10.21(rw,sync,no_root_squash,no_subtree_check)
/mnt/shared 192.168.10.0/24(rw,sync,no_subtree_check)
/mnt/backup
and/home
are shared with the client at IP address192.168.10.21
./mnt/shared
is shared with the entire network192.168.10.0/24
.rw
allows read and write access.sync
forces the server to write changes to disk before replying to the client.no_subtree_check
disables subtree checking, which can improve performance.no_root_squash
allows the root user on the client to have root privileges on the shared directory.
Save the changes and close the file.
Restart the NFS server to apply the changes:
sudo systemctl restart nfs-server
Verify the shared directories:
sudo exportfs -v
**Output**
/mnt/backup 192.168.10.21(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
/home 192.168.10.21(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/mnt/shared 192.168.10.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
Step 3 – Configure Firewall For NFS Server
Open the necessary ports for NFS in the firewall:
sudo firewall-cmd --add-service={nfs,nfs3,mountd,rpc-bind} --permanent
Reload the firewall to apply the new rules:
sudo firewall-cmd --reload
Step 4 – Set up an NFS Client AlmaLinux 9
On the client machine, install the NFS client packages:
sudo dnf install nfs-utils y
Check the available shared directories on the NFS server:
sudo showmount -e 192.168.10.15
This should show /mnt/backup
, /mnt/shared
, and /home
.
Create local directories to mount the NFS shares:
sudo mkdir -p /data /backup /shared
Mount the NFS shared directories:
# sudo mount 192.168.10.15:/mnt/backup /backup
# sudo mount 192.168.10.15:/mnt/shared /shared
# sudo mount 192.168.10.15:/home /data
Verify the mounted directories:
sudo df -h
Step 5 – Confirm Write Access from NFS Client
Test write access to the shared directories. From the client:
# echo "This file from client" > /backup/test-write1.txt
# echo "This file from client" > /shared/test-write2.txt
# echo "This file from client" > /data/alice/test-write3.txt
On the NFS server, verify that the files were created:
# cat /mnt/backup/test-write1.txt
# cat /mnt/shared/test-write2.txt
# cat /home/alice/test-write3.txt
You should see the text "This file from client" in the output of each command.
Step 6 – Configure auto-mount NFS Shared Directory on Client Machine
Configure auto-mounting of the NFS shares so they are automatically mounted at boot time.
First, unmount the shares:
# sudo umount /data /backup /shared
# sudo df -h
Edit the /etc/fstab
file:
sudo vi /etc/fstab
Add the following lines, adjusting the server IP address and mount points as necessary:
192.168.10.15:/mnt/backup /backup nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
192.168.10.15:/mnt/shared /shared nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
192.168.10.15:/home /data nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
auto
enables automatic mounting at boot.nofail
prevents the system from halting the boot process if the NFS server is unavailable.noatime
disables updating the access time on files, which can improve performance.nolock
disables file locking.intr
allows NFS operations to be interrupted.tcp
uses TCP for NFS communication.actimeo=1800
sets attribute cache timeout to 30 minutes.
Verify the /etc/fstab
configuration:
sudo mount -a
Check the mounted file systems:
sudo df -h
That’s it! You have successfully completed the steps to Best Set Up NFS Server and Client on AlmaLinux 9.
Conclusion
You have now successfully set up an NFS server and client on AlmaLinux 9. You can use any RHEL-based distro as your client machine. Also, you have learned to use your NFS service by mounting and exporting and configuring auto-mount NFS-shared directories. This setup allows for centralized data storage and access across your network.
You may be like these articles too:
- Install Apache ActiveMQ on AlmaLinux 8
- How To Install Adminer on AlmaLinux 9
- Install GitHub Desktop on AlmaLinux 9
Alternative Solutions for Sharing Files in AlmaLinux 9
While NFS is a robust and widely used solution for sharing files, alternative methods exist, each with its own advantages and disadvantages. Here are two different ways to solve the problem of file sharing in AlmaLinux 9.
1. Samba (SMB/CIFS)
Samba is an open-source implementation of the Server Message Block (SMB)/Common Internet File System (CIFS) protocol. It allows Linux servers to share files and printers with Windows, macOS, and other Linux clients. Samba is often preferred in environments where Windows clients are prevalent. Setting up a Samba server is another way to Best Set Up NFS Server and Client on AlmaLinux 9.
Explanation:
Samba provides file and print services to SMB/CIFS clients. Unlike NFS, which is primarily used in Unix-like environments, Samba is designed for interoperability with Windows networks. This includes authentication mechanisms, file locking, and access control lists (ACLs) that are compatible with Windows.
Code Example (Simplified Samba Configuration):
First, install the Samba packages:
sudo dnf install samba samba-common samba-client -y
Edit the Samba configuration file (/etc/samba/smb.conf
):
sudo vi /etc/samba/smb.conf
Add a share definition at the end of the file:
[shared]
comment = Shared Directory
path = /mnt/shared
browseable = yes
writable = yes
guest ok = no
read only = no
valid users = your_username
Replace your_username
with the actual username. Then set a Samba password for the user:
sudo smbpasswd -a your_username
Restart the Samba service:
sudo systemctl restart smb nmb
sudo systemctl enable smb nmb
Open the Samba ports in the firewall:
sudo firewall-cmd --add-service=samba --permanent
sudo firewall-cmd --reload
Clients can now access the shared directory using their respective SMB/CIFS clients (e.g., Windows Explorer, macOS Finder).
2. SSHFS (SSH File System)
SSHFS allows you to mount a remote directory over SSH. This is a secure and relatively simple way to share files, especially for personal or small-scale use cases. Because of its secure nature, it could be considered when you want to Best Set Up NFS Server and Client on AlmaLinux 9.
Explanation:
SSHFS leverages the security of SSH to create a file system that can be mounted on a client machine. All data transfer is encrypted, providing a secure channel for file access. SSHFS is particularly useful when you need to access files from a remote server over an untrusted network.
Code Example:
First, install the SSHFS package on the client:
sudo dnf install sshfs -y
Create a local mount point:
sudo mkdir /mnt/sshfs
Mount the remote directory:
sudo sshfs user@remote_server:/path/to/remote/directory /mnt/sshfs
Replace user
with your username on the remote server, remote_server
with the remote server’s address, and /path/to/remote/directory
with the actual path to the directory you want to share.
To unmount the file system:
sudo umount /mnt/sshfs
To make the mount persistent, you can add an entry to /etc/fstab
, but this requires storing the SSH key securely. A more secure approach is to use autossh
to keep the SSH tunnel alive and a systemd service to mount the SSHFS share on boot. This requires more advanced configuration and is beyond the scope of this brief overview.
These alternative solutions offer different approaches to file sharing, each with its own advantages. Samba is ideal for Windows interoperability, while SSHFS provides a secure and simple solution for remote access. Choosing the right method depends on your specific requirements and environment.