Installing NFS on Ubuntu 20.04 server

Muhammed Eren Demir
Geek Culture
Published in
6 min readDec 21, 2021

--

Greetings, I talking about NFS and NFS installing.

NFS, short for Network File System, is a distributed file system
protocol. Share files and directories with others over a network.
It can help you share. programs on remote systems
share information with each other as if they were on the machine and
allow access.

NFS runs in a client-server environment. In other words, if you want to set up NFS to share files between two systems, one must be configured as a server and the other as a client.

The server acts as an administrator, authenticating and authorizing clients for access to shared data. Almost any number of clients can access shared data as simply as any other file or directory in their local storage.

How to install Server for NFS on Ubuntu Server

I have prepared a detailed step-by-step tutorial that will guide you on how to install and set up NFS Server in Ubuntu, so you can start sharing data with other client systems. We will be using Ubuntu 20.04 LTS for this tutorial.

Configuring the Host Server

To install the master server, you must first install the NFS Kernel server.
must. Once done, share with all client systems
You can create and export the files and directories you want.

Let’s finish this thing.

Step 1: Installing Server for NFS Kernel Server

NFS Kernel Server to the Ubuntu system that will run as a server first.
We need to install the package. But before that, download the system packages to make sure nothing gets messed up during the process.
Let’s update.

To do this, type the following command in the terminal:

sudo apt update

For all system package updates, it’s time to install package “nfs-kernel-server” using the following command:

sudo apt install nfs-kernel-server

This will also install some additional packages on your system, including “nfs-common” and “rpcbind”, which are required to set up file sharing.

Step 2: Create NFS Export Directory

After the “nfs-kernel-server” package is installed, you can now create an NFS export directory (known as the “export directory” for short) that will be shared with all client systems. To do this, type the following command inside the terminal.

sudo mkdir -p /mnt/nfs_share

All files that you want to be accessible to the client must be created in this directory. Since we want client systems to have full access to this shared directory, we need to remove any directory permissions that restrict access.

This can be done with the following command:

sudo chown -R nobody:nogroup /mnt/nfs_share/

Once you are done with the above command, move on to the next step.

Step 3: Assign NFS Server Access to Client Systems

Once the Exports directory is ready, you need to grant clients’ systems access to the master server. This permission is defined in the “exports” file located in your system’s /etc folder.

You will need to edit this file and add a few extra command lines to give clients access to the exports directory of their systems. So, open it using the Nano editor by entering the following command in the terminal:

sudo nano /etc/exports

From here, you can provide NFS server access to a single client, several clients, or the entire subnet. For this reading, we will be providing all subnet access to the NFS share.

To do this, you need to add this line to the “export” file.

/mnt/nfs_share subnet(rw,sync,no_subtree_check)

Here you need to change the subnet of your system in the placeholder provided.

Also, let’s look at what the other parts of the command mean:

rw : read/write command
sync : changes are made on disk before they are applied.
no_subtree_check : removes the subtree check.

However, if you only want to grant access to a single client, you can do so using the following syntax:

/mnt/nfs_share client_IP_1(rw,sync,no_subtree_check)

For multiple client joints, you have to do this one by one:

/mnt/nfs_share client_IP_1(rw,sync,no_subtree_check)/mnt/nfs_share client_IP_2(rw,sync,no_subtree_check)

Since the client system has access to the NFS server, it is time to move on to the next step.

Step 4: Export Shared NFS Directory

With all the configurations above available, it’s time to export the shared NFS directory and make it available to client systems.

This is quickly done using the command:

sudo exportfs -a

Do this for NFS to make sure all configurations are in effect.
Restarting the kernel server is required.

sudo systemctl restart nfs-kernel-server

Finally, time to move on to the final step of this setup.

Step 5: Allow Clients Through Firewall

After granting clients access to the NFS server and exporting the shared directory Even after transferring, clients still cannot access the files if they are blocked by the firewall. Therefore, you will need to turn on the firewall for your clients. Your Ubuntu computer already has a default firewall — UFW (Uncomplicated Firewall).

You can type the following command to check if it works on your system:

sudo ufw status

If it shows inactive, you will have to turn it back on using this command:

sudo ufw enable

However, if for some reason it is not installed on your system, you can use this command to install it:

sudo apt install

After installing and enabling UFW on your Ubuntu system, you will need to configure it to allow access to your clients.

Since we are providing NFS access to the entire subnet, we need to use the command:

sudo ufw allow from subnet to any port nfs

However, if you have only allowed NFS access on a per-client basis, you will need to enter the client IP as.

sudo ufw allow from client_IP_1 to any port nfs

And that’s it! You have successfully installed and configured the NFS service on the Server computer.

Configuring the Client System

Next, we will need to install and set up NFS on the client system to access the shared directory. Similar to the previous one, here is a step-by-step guide to help you out.

Step 1: Installing the NFS-Common Package

When installing the client system for NFS sharing, install the “nfs-common” package. We need to set up. As before, you must first update the system package and then nfs-common using the following commands
you must install:

To update packages:

sudo apt update

To install the nfs-common package:

sudo apt install nfs-common

Once complete, proceed to the next step.

Step 2: Let’s create a Mount point

Next, you will need to create a mount point. It will be used to mount NFS shared files from NFS server. To do this, type the following command in the terminal:

sudo mkdir -p /mnt/nfs_clientshare

Step 3: Mount NFS Shared Directory to Client System

The folder you created in the step above works like any other folder on your system. To access the NFS shared directory from the master server, you need to mount it to the new folder:

To do this, you must first know the IP address of the NFS server.
must. Type the following command in the terminal of the server system:

ifconfig

It will bring up the network interface configuration. Server’s IP
is the IP given under “inet” which is 10.0.2.15 in our case.

Using this IP, type the following command in the terminal of the NFS client to finally mount the NFS shared directory to the client system:

sudo mount 10.0.2.15:/mnt/nfs_share /mnt/nfs_clientshare

Step 4: Link To See If Everything Is Working Test it

By following the above steps in order, you have successfully created an NFS server for file and folder sharing between a server system and multiple client systems.

All that remains is to check if everything is working correctly.

To do this, create a new file in the NFS shared directory on the server.
create. You can do this using the command:

cd /mnt/nfs_share/touch file1.txt file2.txt file3.txt

After the process is complete, check the client system to see if these files appear in the NFS shared directory using the command:

ls -l /mnt/nfs_clientshare/

If you see “file1.txt”, “file2.txt” and “file3.txt” files in the list, it means the NFS server is running and you can now start sharing and receiving files between client and server systems.

--

--

Muhammed Eren Demir
Geek Culture

I am software developer. I'm improving myself on Java and devops. I'm working java and devops software in DetaySoft.