10 C
Texas

How To Install and Configure NFS Client on Ubuntu 18.04

In previous tutorial we’ve cover the installation of NFS Server on Ubuntu. In this tutorial, you’ll cover only the configuration of NFS Client on Ubuntu 18.04. So, we already cover the introduction in the previous guide. Let’s start with some basic points.

How NFS Client Works?

NFS client firstly sends a request to the server & mount a remote share that is provided. The permission is set by the NFS Server in ACL configuration file. You can allow or restrict any client that is illustrated in the previous post.

how to install and configure nfs client on ubuntu 18.04

Step 1: Install & Configure NFS Server on Ubuntu 18.04

To Configure NFS Client on Ubuntu you must have installed the NFS Server. Visit the below link if you’ve not see the post

How to install & configure NFS Server on Ubuntu 18.04

Step 2: Install NFS Client on Ubuntu 18.04

- Advertisement -

First of all add the NFS Server DNS records to the /etc/hosts file on your client machine. If you want to use the direct IP address, you can skip this step.

sudo nano /etc/hosts
104.27.130.185 nfs-server.example.com nfs-server

You can confirm that if the serve is reachable or not by typing

ping -c 1 nfs-server
PING nfs-server (104.27.130.185) 56(84) bytes of data.
64 bytes from nfs-server ( 104.27.130.185): 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

Note: Use the server name you’ve added earlier.

As NFS client and NFS Server uses the same parent package nfs-common. So, install it on your machine to acces NFS server shares by running

sudo apt -y install nfs-common

And then update your domain name

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

Step 3: Monitor NFS Share on the Client

As we’ve configured the NFS Share earlier, so now we will mount on the Client.

Discover NFS Exports

First of all discover the NFS exports on NFSv3 or NFSv4 server.

For NFSv3 server use the showmount command

sudo showmount --exports nfs-server
Export list for nfs-server:
/data/nfshare 104.27.130.185

Note: Replace the nfs-server with the NFS server IP address if name is not set

For NFSv4, you’ve to mount the root directory & then look around the available folder shares.

sudo mount nfs-server:/ /mnt/
sudo apt -y install tree
tree /mnt/
/mnt/
└── data
└── nfshare
2 directories, 0 files

If you’ve server that support both methods then you can use both commands & the will work same.

Mount NFS share with mount

Use the mount utility to mount NFS share with the given command

mount -t nfs -o options host:/remote/export /local/directory
  • options: used to specify different conditions or mount options.
  • host: the user or host or network or any domain where to export the file system is mounted.
  • /remote/export: Directory that is being exported.
  • /local/directory: client directory where remote direcotry is mounted.

In our example, this will be

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

Check to confirm

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

use the below command to see the all availabe options for mounting

man mount
man nfs

Persist mount config in /etc/fstab

Configure the /etc/fstab to persist the changes across system reboots.

sudo nano /etc/fstab

And then add the below line with the same syntax as given.

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

In my case it is

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

Now, verify your settings

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

Now, test the permissions

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

You’ll see the file on 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

So, this is how you can configure the NFS Client on Ubuntu 18.04.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article