NFS (Network File system) is a client-server file system protocol which allows multiple system or user to access the same shared folder or file.  The latest is NFS version 4. The shared file will be like if they were stored locally. It provides central management which can be secured with a firewall and Kerberos authentication.

This article will guide you to install the NFS server in Debian 10 and mount it on a client machine.

Lab environment

  • NFS server : 192.168.122.126 (Debian 10)
  • NFS Client :  192.168.122.173 (Any Linux system)

NFS Server Installation

Before proceeding to install the NFS server, first make sure your system is up to date. Run below command

$ sudo apt-get update

Install nfs package using the following command,

$ sudo apt install nfs-kernel-server

Make a directory to share files and folders over NFS server.

$ sudo mkdir –p /mnt/nfsshare

As NFS share will be used by any user in the client, the permission is set to user ‘nobody‘ and group ‘nogroup‘.

$ sudo chown nobody:nogroup /mnt/nfsshare

Make user shared folder has sufficient permission to read and write the files inside it. However, you can set it as per your requirement.

$ sudo chmod 755 /mnt/nfsshare

Add the export information in /etc/exports file

$ sudo vi /etc/exports

Add the following entry at the end of the file.

/mnt/nfsshare 192.168.122.173(rw,sync,no_subtree_check)

Your /etc/export file should look like,

export-file-debian10

Here,

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

Now, export the shared directory.

$ sudo exportfs –a

This shouldn’t show any error. Meaning, your configuration is correct.

If you are running a firewall on your Debian, allow the client to connect to NFS by using the following command,

$ sudo ufw allow from 192.168.122.173/32 to any port nfs

NFS Client Mount

Now, let’s mount our NFS share in the client machine. Install NFS common package,

For Ubuntu Debian / Ubuntu

$ sudo apt install nfs-common

Make a directory to access the shared folder from the server.

$ sudo mkdir -p /mnt/shared_nfs

For permanent mount add the following entry in /etc/fstab file. Open the file using any of your favorite editors.

$ sudo vi /etc/fstab

Add following line at the end of the file,

192.168.122.126:/mnt/nfsshare  /mnt/shared_nfs  nfs4 defaults,user,exec  0 0

Your file should look like,

fstab-file

where,

  • 192.168.122.110:/mnt/nfsshare = shared folder coming from nfs server
  • /mnt/shared_nfs = mount directory in client machine
  • nfs4 = signifies nfs version 4
  • defaults,user,exec = Permit any user to mount the file system also allow them to exec binaries

Mount the NFS file system using command mount as follows.

$ sudo mount -a

You can test the connection by creating a file in /mnt/shared_nfs on the client machine.

Use ‘df -h’ command to see the mount point as shown below,

disk-info-in-debian

Let’s try to create a file with touch command on a NFS share,

$ cd /mnt/shared_nfs
$ touch testFile.txt

If this doesn’t show any error your configuration is fine and you are ready to use NFS share system.

That’s all.  This tutorial guides you to install NFS share on a server and mount in a client. Thank you for reading the article.

Read Also : How to Install GitLab on Debian 10 (Buster)

The post How to Install NFS Server on Debian 10 (Buster) first appeared on LinuxTechi.