How to Install NFS Server on Ubuntu

Wondering how to install the NFS server on Ubuntu?

NFS, better known as Network File System, is a service that allows its users to share and link directories across multiple devices on a single network.

Network File System grants the user access to files present on different systems, provided they’re on the same network. This allows the user to treat the files on different systems as if they’re on the local device.

Aside from those, NFS allows for better management of disk space, common directories, and equal rights of access to external storage devices.

Features like this make NFS a must-have for those in the field of IT and networking.

If you wish to learn how to install the NFS server on Ubuntu, then you’ve come to the right place! Just follow the steps in this guide, and you’ll have an NFS server installed and configured in no time.

So without further ado, let’s begin!

Requirements for NFS.

Before we begin, it’s necessary to mention the prerequisites for NFS to ensure seamless installation and configuration.

For this guide, we’ll be using Ubuntu 20.04 LTS. However, the method shouldn’t be any different from the previous versions of Ubuntu.

Additionally, you’d need two or more devices or servers with root access on the same network to configure NFS.

It should be noted that the device that’s going to act as the host should have Ubuntu installed. The other devices don’t have such restrictions so that they can use any Linux distribution.

Now that we’ve covered the prerequisites, let’s learn how to install the NFS server on Ubuntu.

Step 1: Installing The NFS Kernel Server (Host System).

The first step is to install the NFS kernel on the host system. 

To install the server, we can make use of the Command Terminal.

Follow these steps to install the NFS Kernel on your system:

  1. Start by opening the Command Terminal on your system. You can achieve this by pressing Ctrl + Alt + T on your keyboard.
  2. Once that’s done, type the following command:
$ sudo apt update
Install NFS server on Ubuntu

This will update your system packages and repositories to the latest available version.

  1. Next, type the following in the Command Terminal:
$ sudo apt install nfs-kernel-server
Install NFS server on Ubuntu

This will proceed to install the NFS kernel on your system. The process is automatic, so all that’s left is to wait for completion.

With the installation finished, it’s time to configure NFS.

Step 2: Creating The NFS Directories. 

The next step is to configure your NFS server. This involves the process of creating directories, providing access to client systems, and allowing clients access through your server firewall.

Although the configuration process may seem daunting, you shouldn’t face any problems as long as you follow the steps.

To set up directories, follow these steps:

  1. First, open the Command Terminal.
  2. Next, type in the following command:
$ sudo mkdir -p /mnt/<folder name>

For example,

$ sudo mkdir -p /mnt/NFS_shared
Install NFS server on Ubuntu

This will create the mount directory.

  1. Now, proceed to remove all permissions that would restrict access by typing the following command in the Terminal:
$ sudo chown nobody:nogroup /mnt/NFS_shared
$ sudo chmod 777 /mnt/NFS_shared
chown

This will allow all clients to access the folder named “NFS_shared”

Step 3: Providing Clients Access To NFS Server.

The next step is to provide access to clients.

This can be accomplished with the help of the NFS export file.

To configure the export file, follow these steps:

  1. Start by opening the Command Terminal.
  2. Type the following to open the export file in a text editor:
$ sudo nano /etc/exports
export file

Although we use nano in this guide, the file can be opened on any text editor.

  1. Next, provide access to clients according to your needs.

For a single client, type:

$ /mnt/NFS_shared <client’s IP>(rw,sync,no_subtree_check)

For multiple clients, type:

$ /mnt/NFS_shared <client 1’s IP>(rw,sync,no_subtree_check)
$ /mnt/NFS_shared <client 2’s IP>(rw,sync,no_subtree_check)

Etc.

For clients on the same subnet, type:

$ /mnt/NFS_shared <IP of the subnet>(rw,sync,no_subtree_check)
  1. Lastly, type the following in the Command Terminal to export the recently created directory:
$ sudo exportfs -a
$ sudo systemctl restart nfs-kernel-server
kernel server

With the steps followed correctly, the NFS server should now be configured according to your liking. With this, you can move on to the next step.

Step 4: Provide Client(s) Access Through Firewall.

With the Server configured properly, all that’s left is to provide the client systems access through the host firewall.

For this purpose, you can type the following in the Command Terminal:

$ sudo ufw allow from <client or subnet IP address> to any port nfs

To see the status of the IP, use the following command:

$ sudo ufw status
Install NFS server on Ubuntu

This will display a table of ports and IPs that have access through the firewall.

Step 5: Installing And Configuring NFS (Client System).

With the NFS server now up and running, let’s take a look at how to configure NFS on the client systems.

The process of installation and configuration is fairly simple. As long as you follow the steps correctly, you shouldn’t face any issues.

Follow these steps to install and configure NFS on the client systems:

  1. First, open the Command Terminal.
  2. Next, type the following:
$ sudo apt-get update
$ sudo apt install nfs-common

This will install NFS (Client version) on your system.

  1. Now, type the following to link your system to the available NFS directory created in Step 2.
$ sudo mkdir -p /mnt/NFS_client

This will create a directory in the client system.

To link it with the server folder type:

$ sudo mount <IP of server>:/<server folder> /mnt/<client folder>

For example,

$ sudo mount 192.168.10.1:/NFS_shared /mnt/NFS_client

With the steps followed correctly, the client should be working as intended. This can be tested by trying to access the host file on the client system.

While on the topic of network and server management, it’s necessary to discuss ways to protect your server. One of the best services for protecting your private server data is Fail2ban, which will ensure that your server is never under the threat of any data breaches.

We hope this guide helped you learn how to install the NFS server on Ubuntu. If you have any questions or suggestions to make the guide better, let us know in the comment section below.

Leave a Reply

Your email address will not be published.

Previous Post

How to Use LDD Command in Linux

Next Post

How to Install VNC on Ubuntu

Related Posts