Skip to content

NFS Server

Klemen edited this page Jan 9, 2020 · 4 revisions

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-get update

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

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

$ sudo apt install nfs-kernel-server

Step 2: Create the Export Directory

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 “sharedfolder” in our system’s mnt(mount) directory.

Use the following command, by specifying a mount folder name according to your need, through the following command as root:

$ sudo mkdir -p /mnt/sharedfolder

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 /mnt/sharedfolder
$ sudo chmod 777 /mnt/sharedfolder

Now all users from all groups on the client system will be able to access our “sharedfolder”. 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 client(s) through NFS export file

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:
/mnt/sharedfolder clientIP(rw,sync,no_subtree_check)
  • Multiple clients by adding the following lines in the file:
/mnt/sharedfolder client1IP(rw,sync,no_subtree_check)
/mnt/sharedfolder client2IP(rw,sync,no_subtree_check)
  • Multiple clients, by specifying an entire subnet that the clients belong to:
mnt/sharedfolder subnetIP/24(rw,sync,no_subtree_check)

In this example, we are specifying an entire subnet of all the clients we want to grant access to our export folder (sharedfolder):

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” permissions defined in this file mean that the client(s) can perform:

  • rw: read and write operations
  • sync: write any change to the disc before applying it
  • no_subtree_check: prevent subtree checking

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, in order to make all the configurations take effect, restart the NFS Kernel server as follows:

$sudo systemctl restart nfs-kernel-server