How to Create Linux NFS Fileservers on Debian Server.

NFS is operated in a client-server environment where the server is responsible for managing the authentication, authorization, and management of clients, as well as all the data shared within a specific file system. Upon authorization, any number of clients can access the shared data as if it was present in their internal storage.

In order to set up the host system to share directories, we will need to install the NFS Kernel server on it, and then create and export the directories that we want the client systems to access. Please follow these steps in order to smoothly set up the host side:



Step 1: Install NFS Kernel Server

Before installing the NFS Kernel server, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:

$ sudo apt update && sudo apt upgrade -y

The above command lets us install the latest available version of a software through the Debian repositories.

Now, run the following command in order to install the NFS Kernel Server on your system

$ sudo apt install nfs-kernel-server -y



Step 2: Create the Export Directory

The directory that we want to share with the client system is called an export directory. Here we are creating a directory called ‘Media’ in the ‘Data’ directory.

$ sudo mkdir -p  /Data/Media

As we want all clients to access the directory, we will remove restrictive permissions of the export folder through the following commands:

$ sudo chown $USER:$USER -R /Data/Media
$ sudo chmod 777 -R /Data/Media

Now all users from all groups on the client system will be able to access our “Media”.

You can create as many sub-folders in the export folder as you want, for the client to access.

Step 3: Assign server access to clients

After creating the export folder, we will need to provide the clients the permission to access the host server machine. This permission is defined through the exports file located in your system’s /etc folder. Please use the following command in order to open this file through the Nano editor:

$ sudo nano /etc/exports

Editing this file needs root access; therefore you will need to use sudo with your command. You can also open the file in any of your personal favorite text editors.

Once you have opened the file, you can allow access to multiple clients, by specifying an entire subnet that the clients belong to:


/Data/Media 192.168.1.0/24(rw,sync,no_subtree_check,insecure)

Add the required line(s) to your exports file and then save it by hitting Ctrl+X, entering Y, and then hitting Enter.

Step 4: Export the shared directory

After making all the above configurations in the host system, now is the time to export the shared directory through the following command as sudo:

$ sudo exportfs -a

Finally, restart the NFS Kernel server as follows:

$ sudo systemctl restart nfs-kernel-server -y