vmorecloud - Free IT training download and specialized forum of Cisco and Microsoft VMware virtualization cloud and Linux

Sharing Folders with NFS on Alma Linux 9: A Step-by-Step Guide

85

Alma Linux, a robust and open-source Linux distribution, empowers users with a versatile platform that caters to various server and desktop needs. As users delve into the functionalities of Alma Linux, they often encounter scenarios where the seamless sharing of resources becomes imperative. In this guide, we explore one such crucial aspect—sharing folders through the Network File System (NFS) service.

Efficiently sharing files and directories is a fundamental requirement in any networked environment, facilitating collaborative efforts and providing streamlined access to resources. NFS, a time-tested and widely used protocol, stands as a reliable solution for this purpose.

Prerequisites

Make sure you have root or sudo privileges:

Install NFS Server

Open the command-line interface on your Alma Linux system. This is commonly referred to as the terminal. and type the following command:

sudo dnf install nfs-utils

The command sudo dnf install nfs-utils is used to instruct the package manager (dnf in this case) to install the necessary NFS utilities. These utilities include the software components needed to set up and manage the NFS server on your system.

Create a Directory to Share

Choose or create a directory that you want to share. For example, let’s create a directory named /sharedfolder

sudo mkdir /sharedfolder

The purpose of this step is to create a directory on your file system that you want to share with other devices on the network. This directory will serve as the focal point for NFS, allowing clients to access and interact with its contents.

Set Permissions for the Shared Directory

This step will establish appropriate permissions for the directory that will be shared via NFS. This includes specifying the level of access (read, write, execute) for different users and groups.

sudo chmod -R 755 /sharedfolder

In the above command sudo is used to execute the following command with superuser privileges. It stands for “superuser do.”
chmod: This command is short for “change mode.” It is used to modify the access permissions of a file or directory.
-R: This option stands for “recursive” and is used with chmod to apply the specified permissions not only to the specified directory but also to all its subdirectories and files.

755: These are the numerical permissions assigned to the directory. The three digits represent the permissions for the owner, group, and others, respectively. In this case:

  • 7 (owner): Read (4) + Write (2) + Execute (1)
  • 5 (group): Read (4) + Execute (1)
  • 5 (others): Read (4) + Execute (1)

/sharedfolder: This is the path to the directory for which you are setting permissions. Replace “sharedfolder” with the actual name of your shared directory.

Configure NFS

This step will configure NFS directories to be shared, specify access rules, and set up options to control the behavior of the NFS server.
Edit the /etc/exports File:

  • Open the /etc/exports file using a text editor. This file contains the configuration settings for NFS exports

sudo nano /etc/exports

Define Shared Directories:

Add a line in the /etc/exports file for each directory you want to share. The basic syntax is
/sharedfolder *(options)

Replace /sharedfolder with the path to your shared directory and configure the appropriate options.
Now set access rules based on IP addresses, networks, or specific options. For example

/sharedfolder 192.168.1.0/24(rw,sync,no_root_squash)

This example allows read and write access (rw) to clients in the specified IP range. Save and close the /etc/exports file. Now Apply the changes to the NFS server by running.

sudo exportfs -a

Restart the NFS Service

Restart the NFS service to apply the new configurations.

sudo systemctl restart nfs-server

Adjust Firewall Settings (if necessary)

If a firewall is enabled, allow NFS traffic.

sudo firewall-cmd –permanent –zone=public –add-service=nfs
sudo firewall-cmd –reload

Verify the NFS Configuration

Run the command to confirm that the directory is correctly configured for sharing.

sudo exportfs -v

Once you configure NFS, clients on the network can mount the shared directory using the NFS protocol. You may consider additional configurations, such as setting up user permissions and securing NFS communications, based on your specific requirements and security considerations.

Leave A Reply

Your email address will not be published.