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:
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
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
The system will prompt you with a Y/n option to confirm if you want to continue with the installation. Please enter Y and then hit Enter to continue, after which the software will be successfully installed on your system.
The directory that we want to share with the client system is called an export directory. You can name it according to your choice; here, we are creating an export directory by the name of “Media” in our system’s “Data” directory.
Use the following command, by specifying a mount folder name according to your need, through the following command as root:
$ 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 nobody:nogroup /Data/Media $ sudo chmod 777 /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.
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:
A single client by adding the following line in the file:
/Data/Media clientIP(rw,sync,no_subtree_check,insecure)
Multiple clients by adding the following lines in the file:
/Data/Media 192.168.1.??(rw,sync,no_subtree_check,insecure) /Data/Media 192.168.1.??(rw,sync,no_subtree_check,insecure)
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.
The permissions “rw,sync,no_subtree_check,insecure” permissions defined in this file mean that the clients can perform:
rw: read and write operations
sync: write any change to the disc before applying it
Insecure: for Kodi compatability
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
Now is the time to make some simple configurations to the client machine, so that the shared folder from the host can be mounted to the client and then accessed smoothly.
Before installing the NFS Common application, we need to update our system’s repository index with that of the Internet through the following apt command as sudo:
$ sudo apt update
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 Common client on your system:
$ sudo apt install nfs-common
The system will prompt you with a Y/n option to confirm if you want to continue with the installation. Please enter Y and then hit Enter to continue, after which the software will be successfully installed on your system.
Your client’s system needs a directory where all the content shared by the host server in the export folder can be accessed. You can create this folder anywhere on your system. We are creating a mount folder in the mnt directory of our client’s machine:
$ sudo mkdir -p /mnt/Media
The folder that you created in the above step is like any other folder on your system unless you mount the shared directory from your host to this newly created folder.
Use the following command in order to mount the shared folder from the host to a mount folder on the client:
$ sudo mount 192.168.1.??:/Data/Media /mnt/media
Of course, you can choose to automatically mount the share whenever the client computer starts up. You can do so easily using the /etc/fstab file. An entry in /etc/fstab would look like the following:
192.168.1.??:/Data/Media /mnt/media nfs defaults
Please create or save a file in the export folder of the NFS host server. Now, open the mount folder on the client machine; you should be able to view the same file shared and accessible in this folder.