Ruan Bekker's Blog

From a Curious mind to Posts on Github

Setup a NFS Server on Ubuntu

Quick post on how to setup a NFS Server on Ubuntu and how to setup the client to interact with the NFS Server.

Setup the Dependencies:

1
2
$ apt update && sudo apt upgrade -y
$ sudo apt-get install nfs-kernel-server nfs-common -y

Create the Directory for NFS and set permissions:

1
2
mkdir /vol
chown -R nobody:nogroup /vol

Allow the Clients:

We need to set in the exports file, the clients we would like to allow:

  • rw: Allows Client R/W Access to the Volume.
  • sync: This option forces NFS to write changes to disk before replying. More stable and Consistent. Note, it does reduce the speed of file operations.
  • no_subtree_check: This prevents subtree checking, which is a process where the host must check whether the file is actually still available in the exported tree for every request. This can cause many problems when a file is renamed while the client has it opened. In almost all cases, it is better to disable subtree checking.
1
$ echo '/vol 10.8.133.83(rw,sync,no_subtree_check) 10.8.166.19(rw,sync,no_subtree_check) 10.8.142.195(rw,sync,no_subtree_check)' >> /etc/exports

Start the NFS Server:

Restart the service and enable the service on boot:

1
2
$ sudo systemctl restart nfs-kernel-server
$ sudo systemctl enable nfs-kernel-server

Client Side:

We will mount the NFS Volume to our Clients /mnt partition.

Install the dependencies:

1
$ sudo apt-get install nfs-common -y

Test if we can mount the volume, then unmount it, as we will set the config in our fstab:

1
2
3
$ sudo mount 10.8.133.83:/vol /mnt
$ sudo umount /mnt
$ df -h

Set the config in your fstab, then mount it from there:

1
2
3
$ sudo bash -c "echo '10.8.133.83:/vol /mnt nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0' >> /etc/fstab"
$ sudo mount -a
$ df -h

Now you shoule be able to write to your NFS Volume from your client.

Sources: - 1 2