If you are looking for a reliable way to share files between Linux systems, NFS (Network File System) is the way to go. NFS is a distributed file system protocol that allows a user on a client computer to access files over a network in a manner similar to how local storage is accessed. In this article, we’ll take you through the steps on how to NFS share in Linux.
1. Installation
First, we need to install the necessary packages. On a Debian-based distro like Ubuntu, you can use the apt package manager.
$ sudo apt-get update $ sudo apt-get install nfs-kernel-server nfs-common
On a Red Hat-based distro like Fedora, CentOS, or RHEL, you can use the yum or dnf package manager.
$ sudo yum install nfs-utils nfs-utils-lib
2. Create the Directory to be Shared
Next, let’s create the directory we want to share. In this example, we’ll create a directory called nfs in the /mnt directory.
$ sudo mkdir /mnt/nfs
3. Configure the NFS Exports
Now we need to add our new directory to the NFS exports file. This file controls which directories are shared and how they are shared. Use your preferred text editor to open /etc/exports.
$ sudo nano /etc/exports
Add the following line to the file, replacing 192.168.0.0/24 with the IP range of your network.
/mnt/nfs 192.168.0.0/24(rw,sync,no_root_squash)
Then, save and close the file.
4. Start the NFS Service
We can now start the NFS service with the following command:
$ sudo systemctl start nfs-server.service
5. Test the Configuration
Finally, let’s make sure everything is working properly. On the client machine, use the following command to list the available shares:
$ showmount -e [server IP]
And there you have it! You’ve set up NFS sharing on your Linux machine.
Remember that NFS is not encrypted, so it’s best used in a trusted network environment. For secure file sharing over untrusted networks, consider using SSHFS or a VPN.