NFS, short for Network File Share, is a distributed file system protocol that enables mounting of remote directories on one’s server. It enables accessing of files and folders from a remote host and writing to it over a network, in the same way one would access a local storage file. To access data stored on a remote computer (i.e. nsf server) the server would implement NFS daemon processes to make data available to clients. The system administrator then decides what to make available and ensures it can recognize validated clients. The NFS client on the other hand requests access to exported data by issuing a mount command. If this is successful, the client machine can then view and interact with the file systems within the set parameters.
How do I configure NFS file sharing on Linux Mint? If you are looking at configuring an NFS server on Linux Mint, our today guide will give you a step by step process. We are going to look at how to install and configure NFS server on Linux Mint 20 as well as how to configure NFS client to access the shared directory on the NFS server. We are starting with NFS server.
Step 1: Update packages
I always prefer to have system packages updated before starting any installations.
sudo apt update sudo apt upgrade sudo reboot
Step 2: Install NFS
To install NFS on the server, run the command as shown:
sudo apt install nfs-kernel-server
Step 3: Create share directory
In this step, we are going to create the directory that will be shared to and accessed by the client machines.
$ sudo mkdir -p /mnt/nfs_share
To enable the client machines freely access the shared directories, we ought to remove all the permission restrictions on the shared folder.
$ sudo chown -R nobody:nogroup /mnt/nfs_share $ sudo chmod 777 /mnt/nfs_share
Step 4: Grant Clients Access to the shared directory
The file /etc/exports defines the parameters of the shared directory, including which machines to access and the permissions they are granted on the directory. Open the file with your preferred editor and make the changes as shown:
$ sudo vim /etc/exports
In this file, we specify the shared directory, the clients network and client permissions. Once you open the file, add the following content:
Explanation about the options used in the above command.
- rw: Stands for Read/Write.
- sync: Requires changes to be written to the disk before they are applied.
- No_subtree_check: Eliminates subtree checking.
If you wish to grant access to specific single servers instead, specify their IPs separately as shown in /etc/exports file:
/mnt/nfs_share client_ip_1(rw,sync,no_subtree_check) /mnt/nfs_share client_ip_2(rw,sync,no_subtree_check)
Step 5: Export the shared directory
Having granted access to the client computers, export the NFS share directory and restart the NFS kernel server for the changes to take effect.
$ sudo exportfs -a $ sudo systemctl restart nfs-kernel-server
Step 6: Allow NFS access through the firewall
For the client to access the NFS share, you need to allow access through the firewall otherwise, accessing and mounting the shared directory will be impossible
$ sudo ufw allow from 192.168.30.0/24 to any port nfs $ sudo ufw enable
Install NFS client on Client Machines
Having successfully configured NFS server, we can now go ahead to configure NFS clients to access the shared directory.
Step 1: Install NFS-common package.
Update the client package repositories and install nfs-common package.
$ sudo apt update $ sudo apt install nfs-common
Step 2: Create NFS mount point
We are going to create a directory where we will mount the NFS share from the NFS server.
$ sudo mkdir -p /mnt/nfs_clientshare
Step 3: Mount NFS share on client
Let’s go ahead to mount the NFS share on the created directory
$ sudo mount <nfs-server-ip>:/mnt/nfs_share /mnt/nfs_clientshare
Step 4: Test NFS share on the client
To check if NFS share is working on the client, we are going to write on the server shared directory and check from the client if we can access the same files. On the NFS server, create text files as shown:
$ cd /mnt/nfs_share $ touch test1.txt test2.txt
On the nfs client, check if the files exist
$ ls -l /mnt/nfs_clientshare
You should get an output as below:
You have successfully installed NFS server for file sharing on Linux Mint 20.
Linux learning Videos.
Below are more interesting Linux guides: