How to set up NFS server and client on Debian 10

NFS (Network File System) is a file system protocol that allows users to view and access files and folders on a remote system as if they were stored locally. This is a client-server configuration in which the system that shares storage is called the server, and the system that accesses the storage stored on the server is called the client. NFS allows users or system administrators to mount all or part of a server’s file system on a client system. Clients can then access the mounted files based on specific permissions (read, write) assigned to those files.

Creating an NFS client / server configuration is a simple task that can be completed in a few steps — install, export, mount, and access. In this article, we will explain the process of setting up an NFS server and client on a Debian system so that you can exchange files between remote systems.

We have followed the commands and procedures mentioned in this article on a Debian 10 system.

NFS server

To set up the host system for directory sharing, we will need to install an NFS kernel server on it. To do this, follow these steps:

Step 1. Install the NFS kernel server

Before proceeding with the NFS server installation, update the system repository index by running the following command in Terminal:

$ sudo apt-get update

After the upgrade, install the NFS kernel server by running the following command in Terminal:

$ sudo apt install nfs-kernel-system

Install NFS kernel server

The system can provide you Y / N the ability to confirm the installation. Hit Y to confirm and the installation will begin on your system.

Step 2. Create a directory for export

Now we need to create an export directory that will be shared with client systems. You can mark it as you like. Here we create an export directory named “sharedfolder” in the / mnt directory.

Run the following command specifying the path to the export directory as follows:

$ sudo mkdir –p /mnt/sharedfolder

Create a shared folder

To allow all clients access to the export directory, you need to remove restrictive permissions. To do this, run the following command:

$ sudo chown nobody:nogroup /mnt/sharedfolder

Then apply a new permission that allows everyone to read, write, and access.

$ sudo chmod 755 /mnt/sharedfolder

This will allow all clients to access the shared folder.

Step 3. Set up the export directory

The configuration file for the NFS server is located in the / etc / directory. Here you can specify the directories that you want to provide to your clients, along with the hostnames of the clients. To edit the / etc / exports file using the nano editor, run the following command as sudo in Terminal:

$ sudo nano /etc/exports

Use the following format to provide access to clients:

directory hostname(options)

To allow access to one client, add the following line to it:

/mnt/sharedfolder clientIP(rw,sync,no_subtree_check)

To allow access to multiple clients, add the following line to it:

/mnt/sharedfolder client1IP(rw,sync,no_subtree_check)

/mnt/sharedfolder client2IP(rw,sync,no_subtree_check)

To allow access to multiple clients, specifying the entire subnet, add the following line to it:

/mnt/sharedfolder subnetIP/24(rw,sync,no_subtree_check)

Here we specify the entire subnet for clients to allow them access to our shared directory.

Set up NFS export

When finished editing the / etc / exports file, press ctrl + O to save and ctrl + X to exit the file.

The options (rw, sync, no_subtree_check) in the above file mean that the client has the following permissions:

  • Rweight: read and write operations
  • synchronization: write any change to disk before applying it
  • no_subtree_check: no subtree check

Step 4. Export the shared directory

Then in this step, you will need to export the shared directory specified in / etc / exports. To do this, run the following command in the Terminal:

$ sudo exportfs –a

Then restart the NFS kernel server to apply the configuration changes.

Exporting a shared folder over NFS

Step 5. Configure the firewall

The important thing now is to make sure the server is open for clients to access the shared content. You need to add a rule to allow traffic from specified clients to the NFS port. To do this, use the following syntax:

$ sudo ufw allow from [client-IP or client-Subnet] to any port nfs

In our example, we are going to allow the entire 192.168.72.0 subnet for the NF port:

$ sudo ufw allow from 192.168.72.0/24 to any port nfs

Configure firewall

Now, to check if the rule was successfully added, run the following command in Terminal:

$ sudo ufw status

Check UFW Status

Now our host NFS server is configured and ready to access the specified clients.

Setting up the client machine

We will now configure the client computer to access the server’s export directory. To do this, follow these steps:

Step 1. Install the NFS client

First, update the client computer’s repository index by running the following command in Terminal:

$ sudo apt-get update

Next, install the NFS client application known as NFS common by running the following command in Terminal:

$ sudo apt-get install nfs-common

Configure the client system

The system can provide you Y / N the ability to confirm the installation. Hit Y to confirm and the installation will begin on your system.

Step 2. Create a mount point for the NFS server share.

Now create a mount point that will be used to access the shared content of the server. Here we create a mount point named “sharedfolder_clientr” in the / mnt directory. To do this, we used the following command:

$ sudo mkdir -p /mnt/sharedfolder_client

Create a mount point

Step 3. Connect the server share to the client

In the previous step, we created a mount point. We will now mount the NFS server share to the mount point we created above. The following syntax can be used for this purpose:

$ sudo mount serverIP:/exportFolder_server /mnt/mountfolder_client

For example, in our case, we will mount the shared directory “/ mnt / sharedfolder” from the NFS server to the mount point “/ mnt / mountfolder_client” on our client computer.

$ sudo mount 192.168.72.164:/mnt/sharedfolder /mnt/sharedfolder_client

Where 192.168.72.164 is the IP address of our NFS server.

Mount folder via NFS

The NFS share is now mounted on the client computer.

Step 4. Check the connection

Now it’s time to test our NFS client-server setup. To do this, create a test file or folder in the shared directory of your NFS server. As in the example below, you can see that we have created two folders named “documents” and “music” in the shared directory of our NFS server.

Installed Share in File Explorer

Now open a mount point on your client computer. Here you will see the same files and folders that were created in the server’s shared directory.

Shared folder on the client

That’s all! I hope you learned how to install and configure an NFS server and client on a Debian 10 system. This article also explains how to access an NFS host to access general information.

How to set up NFS server and client on Debian 10

Sidebar