How to Install NFS Server on Debian 10 (Buster)

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)

3 thoughts on “How to Install NFS Server on Debian 10 (Buster)”

  1. This is fine.
    Never the less, i’m using Buster with a BannaPi.
    NFS share can still be declared in fstab.
    But at boot, they are not mounted automaticaly as before.
    I spent quiet a lot of time getting my share nfs mounted, through
    systemd at boot. And i have to say no luck up to know.
    Any idea ?
    Jacques

    1. Never put nfs mounts in /etc/fstab. Instead use the auto-mounter. It automatically mounts/unmounts on demand and can be configured to timeout so you don’t hang your system on nfs.

  2. Hello JACQUES,
    if your storage device is network, please
    add _netdev
    in /etc/fstab
    The final output should like
    192.168.122.126:/mnt/nfsshare /mnt/shared_nfs nfs4 defaults,user,exec,_netdev 0 0

Leave a Reply to Jacques Cancel reply

Your email address will not be published. Required fields are marked *