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 and Configure Squid Proxy on Ubuntu 18.04: Setup Guide

Squid is a full-featured caching proxy server that supports HTTP, HTTPS, and FTP. It is most…

6 minutes ago

Install Chromium on Ubuntu 18.04: The Open-Source Browser Guide

Chromium is a fast, lightweight, open-source web browser developed primarily by Google. It serves as the…

15 minutes ago

Install MySQL Workbench on Ubuntu 18.04: SSH Connections Guide

MySQL Workbench is a cross-platform graphical tool for MySQL database administration. It brings together everything a…

19 minutes ago

VirtualBox Guest Additions on Ubuntu 18.04: Install and Verify

VirtualBox is an open-source, cross-platform virtualization application that lets you run multiple operating systems simultaneously on…

30 minutes ago

Enable SSH on Ubuntu 18.04: Install, Connect, and Manage

SSH (Secure Shell) is a cryptographic network protocol that creates a secure, encrypted connection between your…

23 hours ago

Install Node.js and npm on Ubuntu 18.04: Three Methods Compared

Node.js is an open-source, cross-platform JavaScript runtime that lets you run JavaScript on the server side,…

23 hours ago