How To Configure NFS Server on Ubuntu 18.04

Windows Articles

How to get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...

Today, we are going to learn that how to install & configure NFS Server on Ubuntu 18.04. NFS Server is the abbreviation of Network File System. NFS is distributed file system protocol that provides the facility of remote storage & retrieve data & files within shared network. It enables the client machine to connect to the remote servers in the same way as they are connected locally.
As said earlier that NFS is a client & server file system. So, we require an application on the network machine & NFS storage need to be mounted so that we can access directories & files.
The figure below will clear your concept that how NFS Server & NFS Client connected with the Network.

The main advantage of using NFS shared storage is that system admin can consolidate resources into one centralized server on the network. So, client can access the storage with read & write privileges easily but restricted to the underlying block storage.

Supported Versions of NFS

Here are the some supported version of NFS.

NFSv3 (NFS version 3)

  • Support for safe asynchronous writes and is more robust at error handling than the previous NFSv2
  • Has support for 64-bit file sizes and offsets, allowing clients to access more than 2 GB of file data.

NFSv4 (NFS version 4)

  • It works with firewalls & on the internet.
  • It doesn’t require rpcbind services.
  • NFSv4 supports ACLs (Access Control Lists)
  • It is helpful in stateful operations.

So, let’s move towards the installation of NFS Server on our Ubuntu System. Just follow the below steps.

Step 1: Update your system

As usaul we do, update & upgrade your system

sudo apt update && sudo apt upgrade

Step 2: Set up Hostname for NFS Server

Run the following command to set up a static host-name for NFS server. Make sure that you’ve static IP also.

sudo hostnamectl set-hostname nfs-server.osradar.com --static

Step 3: How To Install NFS Server on Ubuntu 18.04

To install NFS Server on Ubuntu, simply type the below command

sudo apt -y install nfs-kernel-server

Step 4: Start & Enable NFS Services

Then after the installation of NFS start & enable the nfs-server services so that they can be started on boot.

sudo systemctl enable --now nfs-server

Make sure that the services are active by typing

sudo systemctl status nfs-server

Step 5: Exporting NFS Shares

To export NFS, follow the one of the below two methods.

First one is to manaully edit the /etc/exports config file

The second one is by using the exportfs utility on the command line.

Configuration file /etc/exports is responsible to control the file systems that are export to the remote hosts & specific options. Here we see the some syntax rules followed by NFS exports file.

  • Empty lines are ignored.
  • (#) Hash sign is used to comment a line so that it will not run.
  • Wrap larger lines by backslash (\).
  • Every exported file has its own line.
  • Space is used to separate the list of authorized hosts that are placed after an exported file system.

Step 6: How To Prepare NFS Storage Path

To use file system you’ll need to do the partition of your disk. So, run the below command. I recommend you to attach a secondary disk for this purpose.

lsblk | grep sda
sudo parted -s -a optimal -- /dev/sda mklabel gpt
sudo parted -s -a optimal -- /dev/sda mkpart primary 0% 100%
sudo parted -s -- /dev/sda align-check optimal 1
sudo mkfs.xfs /dev/sda1

Now, mount this to the /data directory by

sudo mkdir /data
echo "/dev/sdb1 /data xfs defaults 0 0" | sudo tee -a /etc/fstab
sudo mount -a

Then check the setting to confirm

$ df -hT | grep /data
/dev/sda1 xfs 40G 176M 40G 1% /data

Now, create the directory on /data/nfshare which will be exported to the client.

sudo mkdir /data/nfshare

Step 7: Configure NFS Exports

Edit the /etc/exports file to configure NFS share. Follow the below syntax to modify the file.

export host(options)

You can also specify the multiple hosts by choosing each option for each host like the given syntax

export host1(options1) export host2(options2) export host3(options3)
  • export=directory that is being exported.
  • host=host or user to which the export shared
  • options= what options you can choose.

In this guide, I’m going to show that how I can allow read and write permissions to the remote hosts. By allowing them permissions they can easily make changes to the shared data on the file system. Look at the below example

/data/nfshare        104.27.130.185/24(rw,no_root_squash)

To remove the restriction to the specific network use “*” instead. Note that it is not more secure but is good for local or private networks.

/data/nfshare        *(rw,no_root_squash)

no_root_squash will enable the remote users to have root privileges. It is mostly required for the installation of VM on NFS share.

You can also read the manual about exports by hitting man exports.

man exports

After make changes to the settings just type the exportfs utility to selectively export the directories without starting services again.

sudo exportfs -rav
  • r is used to cause all directoried listed in /etc/exports to export them by making a new export list in /etc/lib/nfs/xtab
  • a is used to export or unexport the all directories. It’ll check the other options before its operation.
  • v is used to display the current progresss.

You also have the option to restart NFS services rather than using exportfs command.

sudo systemctl restart nfs-server

Step 8: Mount NFS Shares on Client Machines

As we’ve finish installing the NFS Server along with configuration. So, in our next guide we will cover the remaining progress that how to mount NFS shares on a client system. Here client can be any host, remote system or a VM on the same server or even the server itself.

So visit the below link to proceed further

How To Configure NFS Client on Ubuntu 18.04

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to get the Nextcloud desktop client on Linux?

Hello friends. We already know how to install a Nextcloud server but now the client is missing. So in this post, you...

How to Backup your call and SMS history in Android

Many times we find ourselves in the situation of having to change our phone, for different reasons, and one of the questions...

Install and configure Apache Guacamole on Debian 10

Hello, friends in this post, you will learn how to install and configure Apache Guacamole in Debian 10. It will be a...

Ubuntu 20.10 available

The new version of Ubuntu is now available, under the code name "groovy gorilla". Ubuntu 20.10 focuses on improving and refining the...

Monitoring Ubuntu 20.04 with Stacer

Normally if we use Linux on a production server, it is important to monitor it. On the other hand, in everyday use, many users...
x