Introduction:
NFS (Network File System) allows you to share directories and files across multiple servers on a network. It provides a simple and efficient way to access remote files as if they were local. In this article, we will walk you through the process of setting up an NFS mount on Rocky Linux 9, enabling seamless file sharing between servers.
Step 1: Install NFS Packages:
Before setting up an NFS mount, ensure that the necessary NFS packages are installed on both the server providing the shared directory (NFS server) and the server accessing the shared directory (NFS client). Open a terminal on both servers and execute the following command to install the required packages:
sudo dnf install nfs-utils
Step 2: Configure the NFS Server:
On the NFS server, the machine hosting the shared directory, perform the following steps:
- Create the shared directory:
sudo mkdir /shared_directory
- Set the appropriate permissions for the shared directory:
sudo chmod -R 755 /shared_directory sudo chown nobody:nobody /shared_directory
- Configure the NFS export by editing the
/etc/exports
file:
sudo nano /etc/exports
Add the following line to the file:
/shared_directory client_ip(rw,sync,no_root_squash)
Replace client_ip
with the IP address of the NFS client server that needs access to the shared directory.
- Save and close the file.
- Export the NFS shares:
sudo exportfs -a
Step 3: Mount the NFS Share on the Client:
On the NFS client server, perform the following steps:
- Create a mount point directory for the NFS share:
sudo mkdir /mnt/nfs_share
- Mount the NFS share on the client server:
sudo mount nfs_server_ip:/shared_directory /mnt/nfs_share
Replace nfs_server_ip
with the IP address of the NFS server.
- Verify the mount:
df -h
You should see the mounted NFS share listed.
Step 4: Configure Auto-Mount (Optional):
To automatically mount the NFS share at system startup, you can set up an entry in the /etc/fstab
file. Open the file on the NFS client server:
sudo nano /etc/fstab
Add the following line to the file:
nfs_server_ip:/shared_directory /mnt/nfs_share nfs defaults 0 0
Save and close the file.
Step 5: Test the NFS Mount:
To verify that the NFS mount is functioning correctly, create a file on the NFS server in the shared directory. Then, check if the file appears in the mounted directory on the NFS client server.
Conclusion:
Congratulations! You have successfully set up an NFS mount on Rocky Linux 9, allowing you to share directories and files between servers seamlessly. By following the step-by-step instructions in this guide, you have configured the NFS server, mounted the NFS share on the client, and optionally set up automatic mounting at system startup. Utilize NFS to streamline file sharing and collaboration within your network, improving efficiency and accessibility across your servers.