A network file system (NFS) is a type of file system that enables the storage and retrieval of data from multiple disks and directories across a shared network.
With NFS you can mount remote directories on your own system. This mount lets you access remote directories as if they are on your own system just like local files.
In this tutorial, let’s see how we can mount an NFS share on Linux systems.
Setting up NFS service
Mounting NFS share on a Linux system requires the NFS client package. Installing this package is very easy but package name differs from Linux distro to distro. So below are the commands for various Linux distros to install the client package.
Install NFS client on Ubuntu and Debian
sudo apt-get install nfs-common
Install NFS client on Arch and Manjaro
sudo pacman -S nfs-utils
Installing NFS client on Fedora and CentOS
sudo yum install nfs-utils
Run above commands on both NFS client and NFS server machines. The above command will install all support files including NFS portmap daemon.
Mounting an NFS file system
Mounting a remote NFS file system is similar to mounting a regular file system. To mount an NFS directory we need to follow the steps below.
First, let’s start by creating a directory to serve as the mount point for the remote NFS share:
sudo mkdir /mnt/share
This directory will be used as a mount point, here mount point is a directory on the local machine where NFS share is mounted.
Now let’s mount the NFS share, Run this command with sudo privileges:
sudo mount -t nfs 192.168.1.10:/share /mnt/share
Here 192.168.1.10 is the NFS server’s IP address, /share is the remote directory on the server, while /mnt/share is the local mount point.
After this command is successfully run no output will be produced. So let’s do a quick test, type the following commands on your client.
cd /mnt/share
mkdir working
Then do a quick check on server if it’s there
cd /share
ls
Now there should be the working directory in /share. But this mount is temporary and will not last after reboot. To make this NFS share permanent on our system across reboots we need to make an entry in /etc/fstab.
Automatically Mounting NFS NFS in Linux
We don’t want to manually mount the NFS file system after every reboot. So for that, we need to add an entry in /etc/fstab. As /etc/fstab contains a list of entries that mounts file systems on system startup.
So to edit /etc/fstab open that file in your favorite editor.
sudo nano /etc/fstab
This will open fstab, now just add the following line in the file.
192.168.1.10:/share /mnt/share nfs defaults 0 0
Here, 192.168.1.10 is the IP address of server, /share is the directory on the server and /mnt/share is the local mount point. And here 0 0 are for dump and pass, 0 for dump means it will not be backed up automatically while 0 for pass means the system will not check for errors at boot time.
How to Unmount NFS file System
When you are done or are no longer in need of the NFS file system you will need to Unmount NFS.
To unmount an NFS share umount command is used, just see the examples below.
umount 192.168.1.10:/share
umount /mnt/share
Use any of the above following commands it will do the work. If you have an entry in fstab file you will also need to remove that line.
This is how to mount NFS in Linux. We hope you like this tutorial and if you like it do share it with your friends. Here are the 10 best text editors for Linux, do take a look at it and tell which one you like the most.