Home

Setting up an NFS server on Ubuntu 20.04

Network File System (NFS) was developed by Sun Microsystems in 1984. It's an RPC-based distributed file system that lets machines on a network access a shared file system as if it were local disk.

In practice, NFS lets multiple machines work with the same set of files as if they all lived on a single drive. You don't have to think about where the bytes physically live. A common use case in larger orgs: instead of every machine carrying its own copy of the same binaries or assets, you put them on one server and let the rest of the fleet mount the shared directory. The server exporting the share is the NFS server; the machines mounting it are NFS clients.

1. Install the NFS server

Install nfs-kernel-server:

bash
apt updateapt install nfs-kernel-server

Check which NFS protocol versions the server supports:

bash
cat /proc/fs/nfsd/versions
bash
-2 +3 +4 +4.1 +4.2

Ubuntu 20.04 ships with NFSv2 disabled. v2 is ancient and effectively unused in the wild — leave it off.

Make the directory you want to export:

bash
mkdir -p /mnt/sharedfolder/

Open the exports file:

bash
nano /etc/exports

Add the share line:

bash
/mnt/sharedfolder/ 192.168.10.0/24(rw,sync,no_root_squash,no_subtree_check)

I'm giving full read/write to the 192.168.10.0/24 subnet here. You can mix and match — different IPs/subnets with different option sets — depending on who should be able to read/write what. The full list of export options lives in the exports(5) man page.

Apply and start the server:

bash
exportfs -asystemctl restart nfs-kernel-server

That's the server side. Now we mount it from a client.

2. Set up the NFS client

Install nfs-common:

bash
apt install nfs-common

Make a local mount point:

bash
mkdir -p /mnt/nfsfolder

You can mount the share temporarily (lost on reboot) or persistently via /etc/fstab.

Persistent mount

bash
nano /etc/fstab

Add:

bash
192.168.10.171:/mnt/sharedfolder/ /mnt/nfsfolder/ nfs rw,hard,intr,rsize=8192,wsize=8192,timeo=14 0 0

Apply without a reboot:

bash
mount -a

Temporary mount

bash
mount -t nfs -o vers=4 192.168.10.171:/mnt/sharedfolder /mnt/nfsfolder

That's it — the same files now appear on both hosts.

On the server:

bash
ll /mnt/sharedfolder

On the client:

bash
ll /mnt/nfsfolder