Published on

Setup a NFS Server on Ubuntu

Authors

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:

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

Create the Directory for NFS and set permissions:

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.
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:

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:

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:

sudo mount 10.8.133.83:/vol /mnt
sudo umount /mnt
df -h

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

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:

Thank You

Thanks for reading, feel free to check out my website, feel free to subscribe to my newsletter or follow me at @ruanbekker on Twitter.