You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

This is a continuation guide on NFS setup on Debian & Ubuntu Linux. In our previous article, we covered the installation and configuration of NFS Server on Debian 10/9 & Ubuntu 20.04/18.04 Linux servers. This guide will only cover how to configure NFS Client on Ubuntu 20.04/18.04 & Debian 10/9.

NFS enables client systems to access files that are stored on a remote shared server over a network and make use of those file systems as if they are locally mounted. The way it works is depicted in the diagram below.

An NFS client sends a call to request and mount a remote share provided it is allowed in the server access control configuration. How to restrict access to subnet/network in NFS server was covered in the NFS server configuration guide.

Step 1: Install and Configure NFS server on Ubuntu 20.04/18.04 & Debian 10/9

For NFS server setup, refer to our guide below:

Install and Configure NFS Server on Ubuntu & Debian

Step 2: Install NFS Client on Ubuntu 20.04/18.04 & Debian 10/9

Add NFS server DNS record to /etc/hosts file on your clients – You can skip this if you want to use the NFS Server IP address directly.

$ sudo nano /etc/hosts
172.20.100.10 nfs-server.example.com nfs-server

Check if the server is reachable via name added.

$ ping -c 1  nfs-server
PING nfs-server (172.20.100.10) 56(84) bytes of data.
64 bytes from nfs-server (172.20.100.10): icmp_seq=1 ttl=64 time=0.693 ms

--- nfs-server ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.693/0.693/0.693/0.000 ms

NFS server and client share the same parent package. The name of the package to be installed is nfs-common. Install it on your servers to access NFS server shares.

sudo apt -y install nfs-common

Update your domain name:

$ sudo nano /etc/idmapd.conf
....
Domain = example.com

Step 3: Mounting NFS Share on the Client

We had configured NFS Share earlier, this is what we will mount on the client

Discovering NFS exports

Before we can mount, let’s discover NFS exports on NFSv3 or NFSv4 server.

With any server that supports NFSv3, use the showmount utility:

$ sudo showmount --exports nfs-server
Export list for nfs-server:
/data/nfshare 172.20.100.0/24

nfs-server can be replaced with NFS server IP address if name resolution is not set.

If NFS server is configured with only NFS v4 support, then mount the root directory and look around for available folder shares.

$ sudo mount nfs-server:/ /mnt/
$ sudo apt -y install tree
$ tree /mnt/
/mnt/
└── data
    └── nfshare

2 directories, 0 files

On servers that support both NFSv4 and NFSv3, both methods work and give the same results.

Mounting an NFS share with mount

The mount utility can be used to mount an NFS share with the following command:

mount -t nfs -o options host:/remote/export /local/directory

Where:

  • options is a comma-delimited list of mount options.
  • host is the host name, IP address, or fully qualified domain name of the NFS server exporting the file system to be mounted.
  • /remote/export is the file system or directory being exported from the server, i.e, directory to be mounted.
  • /local/directory is the client location where /remote/export is mounted.

In our example, this will be:

sudo umount /mnt
sudo mount -t nfs -o nfsvers=4 nfs-server:/data/nfshare /mnt

Confirm:

$ df -hT | grep /mnt
nfs-server:/data/nfshare nfs4       20G  972M   18G   6% /mnt

To see all mount options, refer to man pages.

$ man mount
$ man nfs

Persist mount configuration in /etc/fstab

To persist the changes across system reboots, Configure NFS mounting on /etc/fstab.

$ sudo nano /etc/fstab

Add a line like with the following syntax to the end of file.

host:/remote/export  /local/directory   nfs defaults   0 0

In my case, this will be.

nfs-server:/data/nfshare  /mnt nfs defaults 0 0

Test your settings:

$ sudo umount /mnt
$ sudo mount -a
$ df -hT | grep /mnt
nfs-server:/data/nfshare nfs4       20G  972M   18G   6% /mnt

Try write files to the directory.

echo "Test file1" | sudo tee /mnt/testfile1
echo "Test file2" | sudo tee /mnt/testfile2

The file should be seen on the NFS server block device.

$ sudo apt -y install tree
$ tree /data/nfshare/
 /data/nfshare/
 ├── testfile1
 └── testfile2
 0 directories, 2 files

$ cat /data/nfshare/testfile1 
Test file1
$ cat /data/nfshare/testfile2
Test file2

Hurray!. You have configured NFS client successfully on a Ubuntu / Debian system. Stay connected for more informative guides as you go through:

Best Linux Books for Beginners & Experts 2019

Install and Configure Samba Server Share on Debian / Ubuntu

Create Wi-Fi Hotspot on Ubuntu / Debian / Fedora / CentOS / Arch

Install Microsoft Teams on Fedora / Ubuntu / Debian Linux

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF