How to Configure/Setup NFS client on Ubuntu 20.04

Share this article

In our previous articles, How to install & configure NFS Server on CentOS 8 we set up an NFS server and in How to Configure/Setup NFS client on CentOS 8 article we set up the NFS client. In this article, we will further discuss how to configure the NFS client but on Ubuntu 20.04.

Our setup.

The below-mentioned image shows a depiction of our NFS infrastructure setup.

  • NFS server:
    • IP : 192.168.122.105
    • Hostname : test.nfs-server
    • OS: CentOS 8
  • NFS Client1 :
    • IP: 192.168.122.207
    • Hostname: test.nfs-client-centos
    • OS: CentOS 8
  • NFS Client2:
    • IP: 192.168.122.1
    • Hostname: test.nfs-client-ubuntu
    • OS: Ubuntu 20.04

In this article, we will set up an NFS client2 which will be running on Ubuntu 20.04. For NFS client1 you can refer to How to Configure/Setup NFS client on CentOS 8.

Install NFS client

In order to install the NFS client, it uses the same nfs-common package. First run the update command so that it can install latest version then run the install command, both the commands are mentioned below.

sudo apt update
sudo apt install nfs-common

Miscellaneous configuration

/etc/hosts entry

This conf is totally optional. If you are using a local DNS name (admin uses it for simplicity) in your mount configuration then it is important to have it. Enter the following line into /etc/hosts file

192.168.122.105 test.nfs-server

Verify the above entry by running ping command. If it is able to ping the nfs-server that means the client is able to resolve the entry.

foofunc@test ~$ ping test.nfs-server -c 4 
PING test.nfs-server (192.168.122.105) 56(84) bytes of data.
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=1 ttl=64 time=0.452 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=2 ttl=64 time=0.461 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=3 ttl=64 time=0.468 ms
64 bytes from test.nfs-server (192.168.122.105): icmp_seq=4 ttl=64 time=0.545 ms

--- test.nfs-server ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3061ms
rtt min/avg/max/mdev = 0.452/0.481/0.545/0.037 ms
foofunc@test ~$

Create directory for mounting

For the sake of simplicity, I will create a directory in the /mnt/ where I will mount the share from the nfs-server.

mkdir -p /mnt/mount_test

NFS share/export mounting

Verify the export list

Check the export list for the nfs-server. Use the following command.

showmount --exports <ip_address/Host_name of the nfs-server>

See the command output:

foofunc@test ~$ sudo showmount --exports test.nfs-server
Export list for test.nfs-server:
/mnt/export/demo 192.168.122.201
foofunc@test ~$

Mount the NFS Share

The mount package is used to mount the NFS share. mount package is by default available in Linux.

Run the following command to mount the remote share directory,

mount -t nfs -o options <nfs-server:/remote/share_directory>  </local/mount_directory>

The above command use the following options

  • -t: is used to indicate the filesystem type. For that we have mentioned type of file system is nfs
  • -o : Use the specified mount options. Multiple options can be passed with comma.
  • nfs-server:/remote/share_directory: nfs-server share directory which we are going to mount on our client machine.
  • /local/mount_directory: this arument is path to local directory which will be the mointing point in client machine.

Following command, I have run to mount the share for nfs-server

root@test ~# mount -t nfs -o nfsvers=4 test.nfs-server:/mnt/export/demo /mnt/mount_test
root@test ~#

Verify

In order to check the filesystem and mounted point use the df command.

root@test ~# df -kh
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  856K  797M   1% /run
/dev/mapper/cl-root                 20G  9.6G  9.1G  52% /
tmpfs                              3.9G   64K  3.9G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                          976M  220M  690M  25% /boot
tmpfs                              798M     0  798M   0% /run/user/0
test.nfs-server:/mnt/export/demo    50G   12G   39G  24% /mnt/mount_test
root@test ~# 

Make mounting persistent

In the previous section, we have done the mounting but this mount is not persistent which means if we reboot the system after reboot we will don’t have NFS filesystem in our client machine. Therefore, to make it persistent we need to do entry in /etc/fstab.

Syntax for /etc/fstab entry

 nfs-server:/remote/share_directory /local/mount_directory   nfs defaults   0 0

In our case, we have the following entries in the /etc/fstab file.

root@test ~#  cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-yyCJpEJ7umYY6MjNBb79mpYchXJDdFsN515fWkIaf2k8u6AGoM7OkFjlPTOTaXYv / ext4 defaults 0 0
# /boot was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/35d3eb20-f0ae-4833-b3ef-55595e77b5c4 /boot ext4 defaults 0 0
/swap.img	none	swap	sw	0	0
test.nfs-server:/mnt/export/demo /mnt/mount_test nfs defaults   0 0
root@test ~#  

The easiest way to check the validity is to reboot the system or you can unmount or then use /etc/fstab entry to mount the filesystem. Use the following command to reboot or do the unmount and then again mount with fstab entry.

sudo reboot 

or

sudo umount /mnt/mount_test
sudo mount -a

Verify

In order to check the filesystem and mounted point use the df command.

root@test ~# df -kh
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  856K  797M   1% /run
/dev/mapper/cl-root                 20G  9.6G  9.1G  52% /
tmpfs                              3.9G   64K  3.9G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                          976M  220M  690M  25% /boot
tmpfs                              798M     0  798M   0% /run/user/0
test.nfs-server:/mnt/export/demo    50G   12G   39G  24% /mnt/mount_test
root@test ~# 

Summary

In this article, we have explained how to set up the NFS client and how to mount the NFS filesystem in Ubuntu 20.04. This article is the next part of How to install & configure NFS Server on CentOS 8. This is basically the same configurations that we did in NFS client set up on CentOS 8

In case you face any issues running the command feel free to comment.

Leave a Comment

Your email address will not be published. Required fields are marked *