Setup NFS Server


Minimum requirements

  • Linux, this page will cover Alpine, Debian and RHEL based configurations
  • 1-2 CPU cores
  • 1GB memory
  • 10gb storage (All depends on what your applications will require)

Install the required packages

OS:
sudo apk update           # Update apk cache
sudo apk add nfs-utils    # Install NFS utils/server
sudo rc-update add nfs    # Start NFS server on boot
sudo apt update                                   # Update apt cache
sudo apt install -y nfs-kernel-server rpcbind     # Install NFS server
sudo systemctl enable --now nfs-server rpcbind    # Start and enable nfs-server on boot
sudo yum -y update                                # Update yum cache
sudo yum -y install nfs-utils                     # Install NFS server
sudo systemctl enable --now nfs-server rpcbind    # Start and enable nfs-server on boot

Configure shares

This guide will use /share/nfs as an example, this guide wil also be allowing access to the share from 10.10.1.0/28 only

sudo mkdir -p /share/nfs
# mount disk via fstab if you are using a dedicated disk, not covered here
echo '/share/nfs 10.10.1.0/28(rw,no_root_squash,async,fsid=0,no_subtree_check)' | sudo tee -a /etc/exports

If you want to enable a share to multiple ip’s or subnets you can add another ip/option block to the line e.g.

/etc/exports

/share/nfs    10.10.1.0/28(rw,no_root_squash,async,fsid=0,no_subtree_check)    192.168.1.22(rw,no_root_squash,async,fsid=0,no_subtree_check)

Apply the configuration change

Run sudo exportfs -rav to apply the share changes from the exports file. (no service restart required.)

exportfs

maintain table of exported NFS file systems

-a

Export or unexport all directories.

-r

Reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports. This option removes entries in /var/lib/nfs/etab which have been deleted from /etc/exports, and removes any entries from the kernel export table which are no longer valid.

-v

Be verbose. When exporting or unexporting, show what’s going on. When displaying the current export list, also display the list of export options.