The cart is empty

NFS (Network File System) is a protocol that allows remote access to files over a network as if they were stored locally. This article provides a step-by-step guide on how to mount NFS on a Linux system, both on the server and client side.

What is NFS and Why Use It?

NFS is a network protocol that allows computers to share file systems within a local network. NFS is ideal for scenarios where files need to be shared between servers and clients in a multi-user environment. It’s an efficient way to centralize data and provide easy access for various users.

Step 1: Install Required Packages

First, you need to install the necessary packages on both the server and client machines. On most distributions like Ubuntu or Debian, you can do this with the following command:

sudo apt update && sudo apt install nfs-kernel-server

For Red Hat and other RPM-based distributions, use the command:

sudo yum install nfs-utils

Step 2: Configure the NFS Server

On the server side, you need to define the directories that will be shared over NFS. These directories are configured in the /etc/exports file. For example, add the following line to this file:

/mnt/data 192.168.1.0/24(rw,sync,no_subtree_check)

This example states that the directory /mnt/data will be accessible to all machines in the 192.168.1.0/24 network, with read and write permissions (rw), synchronized writing, and no subtree checking.

Step 3: Restart NFS Service

After configuring the /etc/exports file, you need to restart the NFS server for the changes to take effect:

sudo systemctl restart nfs-kernel-server

If you're using firewalld or another firewall, ensure that the necessary ports for NFS are open:

sudo firewall-cmd --permanent --add-service=nfs

Then reload the firewall:

sudo firewall-cmd --reload

Step 4: Mount NFS on the Client

On the client machine that wants to connect to the NFS server, you need to have the NFS client packages installed. On Ubuntu and Debian, use:

sudo apt install nfs-common

For Red Hat and RPM distributions:

sudo yum install nfs-utils

After installation, you can mount the shared NFS directory using the mount command. For example:

sudo mount 192.168.1.100:/mnt/data /mnt/local_mount

In this example, you're mounting the /mnt/data directory from the NFS server with IP address 192.168.1.100 to the local directory /mnt/local_mount.

Step 5: Automating NFS Mount at Boot

To ensure the NFS directory is automatically mounted at system startup, you can modify the /etc/fstab file. Add the following line:

192.168.1.100:/mnt/data /mnt/local_mount nfs defaults 0 0

This ensures that NFS will be automatically mounted after a reboot.

Troubleshooting

If you encounter issues with the connection, check that permissions and access rights are correctly set on the server. The showmount command can help verify which directories are available:

showmount -e 192.168.1.100

Also, check the status of the NFS service on the server:

sudo systemctl status nfs-kernel-server 

NFS is a powerful tool for sharing files across a network, and once configured properly, it provides a fast and efficient way to access data. By following this guide, you should be able to mount NFS easily on your Linux system.