Set Up NFS Server and Client on AlmaLinux 9

In this guide, we want to teach you to Set up an NFS Server and Client on AlmaLinux 9. NFS is used in a centralized environment where users or client computers can store and access data on one centralized remote server. Now follow the steps below to complete your NFS server and client setup.

How To Set Up NFS Server and Client on AlmaLinux 9?

To complete this guide, you must have access to your server as a non-root user with sudo privileges and set up a basic firewall. For this purpose, you can follow this guide on Initial Server Setup with AlmaLinux 9.

Also, you need a client machine. You can use any RHEL-based distribution.

Step 1 – Install NFS Server on AlmaLinux 9

First, you need to run the system update by using the command below:

sudo dnf update -y

Then, use the following command to install the NFS utility package on your server:

sudo dnf install nfs-utils -y

Next, you need to edit the /etc/idmapd.conf file and change the Domain option to your hostname. Open the file with your desired text editor, here we use vi:

sudo vi /etc/idmapd.conf

Find the Domain directive and uncomment it by removing “#” from the beginning of the line and changing the value to your hostname or FQDN.

Domain = almalinux-server

When you are done, save and close the file.

Manage NFS Server Service

At this point, you need to start and enable your NFS service on AlmaLinux 9 by using the following commands:

# sudo systemctl start nfs-server
# sudo systemctl enable nfs-server

Verify your NFS server is active and running with the following command:

sudo systemctl status nfs-server

You should get the following output:

Output
● nfs-server.service - NFS server and services
     Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; prese>
     Active: active (exited) since Tue 2023-06-06 06:22:44 EDT; 48s ago
   Main PID: 75513 (code=exited, status=0/SUCCESS)
        CPU: 34ms
...

Step 2 – Create NFS shared Directories on AlmaLinux 9

At this point, you need to set up the shared directory for clients. To do this, you need to create two directories /mnt/shared and /mnt/backup by using the following command:

sudo mkdir -p /mnt/shared /mnt/backup

Then, set the correct permissions and ownership for these directories by using the commands below:

# sudo chown -R nobody:nobody /mnt/shared /mnt/backup
# sudo chmod 775 /mnt/shared /mnt/backup

Next, use the following command to create a new configuration file:

sudo vi /etc/exports

Add the following content to the file:

/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)

Note: Here we set up three shared directories /mnt/backup and /home for the client 192.168.10.21, and /mnt/shared for the entire network in 192.168.10.0/24.

When you are done, save and close the file.

Then, restart the NFS server to apply the changes:

sudo systemctl restart nfs-server

Also, you can check the list of shared directories on the NFS server by using the command below:

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

At this point, you need to open NFS services through firewalld by using the command below:

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

Then, reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Step 4 – Set up an NFS Client AlmaLinux 9

At this point, you can set up your NFS client. Here our client machine is AlmaLinux 9. You can use any RHEL-based distribution.

From your client machine, run the command below to install the NFS:

sudo dnf install nfs-utils y

Then, run the following command to check available shared directories on the NFS server, here our NFS server is 192.168.10.15.

sudo showmount -e 192.168.10.15

In your output, you should see three different shared directories available on your NFS server, /mnt/backup, /mnt/shared, and /home.

Next, you need to create new directories /data, /backup, and /shared. These will be used to mount NFS-shared directories.

To do this, run the following command:

sudo mkdir -p /data /backup /shared

Then, mount the NFS-shared directories by using the command below:

# 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

Finally, you can verify your NFS-shared directories with the command below:

sudo df -h

Step 5 – Confirm Write Access from NFS Client

At this point, you need to be sure to read and write access to the shared directories.

From your NFS client machine, create new files /backup/test-write1.txt/shared/test-write2.txt, and /home/alice/test-write3.txt by using the commands below:

# 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

Now you need to be sure that these files are available on the NFS server. To do this, run the commands below from your NFS server:

# 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 your output.

Step 6 – Configure auto-mount NFS Shared Directory on Client Machine

At this point, you can set up auto-mount of the NFS server on the client machine. So, whenever the client machine is restarted, the NFS shared directory will be mounted automatically during the boot. You can do this by using the /etc/fstab file.

First, you need to umount and verify NFS shared directories on the client machine by using the following commands:

# sudo umount /data /backup /shared
# sudo df -h

Then, open the /etc/fstab file with your favorite text editor, here we use vi:

sudo vi /etc/fstab

Add the following content to the file:

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

Note: Be sure to customize the details of shared directories and target mount directories.

When you are done, save and close the file.

Verify your /etc/fstab file configuration with the command below:

sudo mount -a

Finally, you can get your client’s mounted file systems list with the command below:

sudo df -h

That’s it you are done.

Conclusion

At this point, you have learned to 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.

Hope you enjoy it. 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

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!