How to Install the NFS Server on Debian 10

Install the NFS server on Debian 10 and seamlessly access the files and folders on any desired remote system. What the NFS does is allow users to view, store, and even update files on a remote computer. 

NFS or Network File System refers to a file system protocol built to let users flexibly view, access, and manage the files stored on a remote system similar to how they would’ve operated the files stored locally. To put it in simple words, the NFS server utility helps create a central management environment that can even be secured.

It is a form of client-server setup where you can mount the desired section of a server file system on the client’s system, eventually helping the clients gain access to the mounted files. In this article, you’ll learn how to install the NFS server on Debian 10, mount it on the desired client system, and efficiently employ the utility.

How to Install the NFS Server on Debian 10

Considering you’ve all the required resources ready, let us learn how to install the NFS server on Debian 10. 

Step 1: Update the System Repository

It is always a good idea to update the system repository before installing any utility, and the NFS server is no exception. 

Launch the Terminal using the “Ctrl+Alt+T” key combination.

Run the following command:

$ sudo apt-get update
updating apt repository

Step 2: Install the NFS Server on Debian 10

Once you’ve updated the system repository, you can now install the NFS Kernel server. Doing it is pretty simple. Just launch the Terminal and run the following command:

$ sudo apt install nfs-kernel-system
install the nfs server on debian 10

You’ll then see a Y/N prompt to confirm the installation. Input Y and hit the Enter button.

Step 3: Verify the NFS Server Installation

The last thing to do is confirm if the NFS server installation is successful or not. For that, invoke the $ nfs --version command. In case it returns with something like Command 'nfs' not found, it means you’ll need to re-install the NFS server on your system.

Creating the Export Directory

The first thing to do is create an export directory. Keep in mind that the same directory will be shared with the client’s systems. The good thing is that you can label the directory as per your requirements. For instance., I’ll create a folder in the /mnt directory and name it workingfolder.

Launch the Terminal

Run the following command in the following format:

$ sudo mkdir –p /mnt/workingfolder
creating an export folder

Accessing Flexible Permission

It is crucial to grant all-clients access permission to make the export directory operational. In other words, you’ll need to remove all the existing restrictive permissions. Run the chown command alongside the nobody flag in the following format:

$ sudo chown nobody:nogroup /mnt/workingfolder
assigning flexible permission

After that, apply new permission allowing everyone to read, write, and even execute access. For that, use the chmod command.

$ sudo chmod 755 /mnt/workingfolder
applying permissions

Configuring the Export Directory

If you don’t know, creating an export directory and granting flexible permissions isn’t enough as you’ll need to configure it properly. Before I let you know how, you must be aware that the configuration file for the concerned NFS server is usually located at your system's/etc/ directory.

By configuring the export directory, you can seamlessly specify the desired directories that you want your clients to access alongside their corresponding hostnames. Bringing all the necessary edits to the /etc/exports file is easy, but you’ll need to employ an editor. I’ll be using the nano editor, for instance.

Open the Terminal and run the following command. Make sure you’ve got the sudo privileges.

$ sudo nano /etc/exports
install the nfs server on debian 10 and configure exports

Maintain the following format and assign access to the desired clients:

directory hostname(options)

Allowing Access to Single Client

If you want to allow access to a single client, copy-paste the following line:

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

Allowing Access to Multiple Clients

For allowing access to multiple clients, simply input the following line according to the desired number.

/mnt/workingfolder client1IP(rw,sync,no_subtree_check)
/mnt/workingfolder client2IP(rw,sync,no_subtree_check)
/mnt/workingfolder client3IP(rw,sync,no_subtree_check)

Allowing Access to Multiple Clients While Specifying Subnet

Do you want to allow access to multiple clients and specify a whole subnet at the same time? Well then, add the following line in it:

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

Saving the Edits

As soon as you’re finished editing the /etc/exports file, go ahead and save it. Simply use the Ctrl+O key combination for doing so. After that, hit Ctrl+X and exit the file.

The terms rw, sync, no_subtree_check used above signify different sorts of permissions that you can provide your clients with. Here is what I mean to say:

  • rw: It allows access to read and write operations
  • sync: With this, your client can write any change to the disc before eventually applying it
  • no_subtree_check: This allows no subtree checking

Exporting the Shared Directory

Until this point, you know how to install the NFS server on Debian 10 and configure the corresponding export directory. Next, you’ll understand the process involved in exporting the shared directory. The shared directory is usually listed in /etc/exports. For initiating the export, all you need to do is run the following command in Terminal with sudo privileges:

$ sudo exportfs –a
exporting shared directory

Finally, restart the NFS Kernel server to ensure that all the alterations in the file configuration are successfully applied.

Configuring Firewall

Similar to granting flexible permission, verifying that the server is operational and open for the concerned clients is equally vital. You must add a specific rule that allows traffic to the NFS port. For doing this, invoke the ufw allow command in the following form:

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

Suppose you wish to allow the whole 192.168.52.1 subnet to the NF port. In that case, run the following command:

$ sudo ufw allow from 192.168.52.1/24 to any port nfs
configuring firewall

Make sure you verify whether or not the rule is successfully added. Simply launch the Terminal and run the following command:

$ sudo ufw status

Voilà, the NFS server is properly configured, and the desired clients can now access it.

Install the NFS Server on Debian 10: Client Machine

After installing and configuring the NFS server on your system, the next thing to do is configure the client’s machine so that they can access the server’s export directory. 

Install NFS client

As usual, start by updating the repository index of your client’s machine by running the following command:

$ sudo apt-get update
updating apt repository

After that, install an application called NFS common by invoking the following command:

$ sudo apt-get install nfs-common
install the NFS server on debian 10

Creating a Mount Point for the Shared Folder of NFS sever

Next up, create a mount point that will help the client in accessing the shared content. You can name it desirably and suppose it is workingfolder_clientr in the /mnt directory, run the command as:

$ sudo mkdir -p /mnt/workingfolder_client
creating mount point

Mount the Shared Directory Server on the Client

After creating a mount point, you’ll now mount the NFS shared directory server to it. You can run the following command for this purpose:

$ sudo mount serverIP:/exportFolder_server /mnt/workingfolder_client
mounting the shared directory

Now you’re ready to test the NFS client-server setup. Create a test file in the NFS server shared directory and open the mount point on your client machine. In case you’re able to see all the files and folders that you created earlier, it signifies that the process has been concluded successfully.

And with that, I’m done guiding you on how to install the NFS server on Debian 10. Here I’ve uncovered everything from getting your system ready to even making your client’s machine capable of accessing the server’s export directory.

If this guide helped you, please share it.

Leave a Reply
Related Posts