NFS (Network File System) is a distributed file sharing protocol that lets you mount remote directories on a local machine and work with the files as if they were stored locally. It is a practical choice for sharing data between Linux servers on a private network.
NFS does not encrypt traffic by default and does not provide user authentication. Access control is managed at the IP address or hostname level. If you need encrypted file sharing, SSHFS is a good alternative.
This guide covers how to configure an NFS server on Ubuntu 18.04 and how to connect Linux clients to it. The example uses server IP 192.168.33.10 and clients on the 192.168.33.0/24 subnet.
<strong>Prerequisite:</strong> You need sudo access on both the server and client machines.
Install the NFS server package:
bashsudo apt install nfs-kernel-server
The NFS service starts automatically. Ubuntu 18.04 enables NFSv3 and NFSv4 by default. NFSv2 is disabled.
Create the NFS root and export directories
With NFSv4, the best practice is to create a global NFS root directory and bind-mount your actual shared directories into it. This example shares /opt/backups and /var/www:
bashsudo mkdir -p /srv/nfs4/backupssudo mkdir -p /srv/nfs4/www
Bind-mount the real directories into the NFS root:
bashsudo mount --bind /opt/backups /srv/nfs4/backupssudo mount --bind /var/www /srv/nfs4/www
To make these bind mounts survive a reboot, add the following lines to /etc/fstab on the server:
/opt/backups /srv/nfs4/backups none bind 0 0/var/www /srv/nfs4/www none bind 0 0
The /etc/exports file controls which directories are shared, which clients can access them, and with what permissions. Open it for editing:
bashsudo nano /etc/exports
Add your export rules. This configuration shares the NFS root to the whole subnet, the backups directory as read-only to the subnet (with write access for one specific client), and the web directory to a single host:
/srv/nfs4 192.168.33.0/24(rw,sync,no_subtree_check,crossmnt,fsid=0)/srv/nfs4/backups 192.168.33.0/24(ro,sync,no_subtree_check) 192.168.33.3(rw,sync,no_subtree_check)/srv/nfs4/www 192.168.33.110(rw,sync,no_subtree_check)
Key options explained:
nobody/nogroup account for securityApply the changes:
bashsudo exportfs -ra
Run this command every time you modify /etc/exports.
Open the firewall port
If UFW is enabled, allow NFS traffic from your client subnet:
bashsudo ufw allow from 192.168.33.0/24 to any port nfs
On each client machine, install the NFS client tools:
bashsudo apt install nfs-common
Create mount point directories and mount the remote shares. With NFSv4, omit the NFS root from the path — use /backups instead of /srv/nfs4/backups:
bashsudo mkdir -p /backupssudo mkdir -p /srv/wwwsudo mount -t nfs -o vers=4 192.168.33.10:/backups /backupssudo mount -t nfs -o vers=4 192.168.33.10:/www /srv/www
Verify the mounts are active with df -h. To make them permanent across reboots, add the following to /etc/fstab on the client:
192.168.33.10:/backups /backups nfs defaults,timeo=900,retrans=5,_netdev 0 0192.168.33.10:/www /srv/www nfs defaults,timeo=900,retrans=5,_netdev 0 0
To unmount a share when you no longer need it:
bashsudo umount /backups
Your NFSv4 server is now configured on Ubuntu 18.04 and clients can mount the shared directories. For production environments with sensitive data, consider enabling Kerberos authentication or switching to SSHFS for encrypted file sharing. Leave a comment below if you run into any issues.