How To

Configure NFS Server on Ubuntu 18.04: Setup and Mount Guide

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>&nbsp;You need sudo access on both the server and client machines.

Configure the NFS Server on Ubuntu

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

Define NFS Exports

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:

  • fsid=0 – marks this directory as the NFSv4 root
  • crossmnt – required for sub-directories of an exported directory to be accessible
  • sync – writes data to disk before confirming to the client
  • root_squash – enabled by default; maps root users from clients to the nobody/nogroup account for security

Apply 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

Connect NFS Clients

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.

Cyber Defence

Recent Posts

Install phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

2 days ago

Install Zabbix on Ubuntu 18.04: Server Setup with MySQL Backend

Zabbix is a mature open-source infrastructure monitoring platform that collects metrics from network devices, servers, virtual…

2 days ago

Install Gradle on Ubuntu 18.04: Set Up OpenJDK and Environment

Gradle is a powerful open-source build automation tool used primarily for Java, Kotlin, Groovy, and Android…

2 days ago

Install TeamViewer on Ubuntu 18.04: Download the .deb and Set Up

TeamViewer is a proprietary cross-platform remote access application for remote control, desktop sharing, file transfer, and online meetings. It is one of the most widely used remote support tools in the world, available for Windows, macOS, Linux, iOS, and Android. TeamViewer is not included in the Ubuntu repositories because it is proprietary software. This guide covers how to install TeamViewer on Ubuntu 18.04 using the official .deb package. The same steps apply to Ubuntu 16.04, Debian, Linux Mint, and Elementary OS. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Install TeamViewer on Ubuntu: Download the .deb Package Download the official TeamViewer .deb package. The _amd64.deb suffix indicates this package is for 64-bit x86-64 systems. For ARM-based machines, download the appropriate package from the TeamViewer Linux downloads page: bashwget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb Install the package using apt. The ./ prefix tells apt this is a local file path, not a package name from the repositories:…

2 days ago

Install Nagios Core on Ubuntu 18.04: Build from Source Guide

Nagios is one of the most widely used open-source infrastructure monitoring systems in the world. It…

2 days ago

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is…

2 days ago