UBUNTU SERVER · LINUX NETWORKING · STEP-BY-STEP TUTORIAL

How to Set Up an NFS Server and Client on Ubuntu 26.04.2

By Khurram Shahzad · Linux Tutorial ·

Ubuntu 26.04 NFS server and client sharing files across a local network

Network File System (NFS) allows Linux computers to share directories across a network. Once configured, a client can access a remote directory almost like a local filesystem. In this tutorial, you will install an NFS server and client on Ubuntu 26.04.2, configure a restricted network export, mount the shared directory, test read and write access, and configure persistent mounting after reboot.

This guide follows Ubuntu Server’s documented NFS workflow and uses a private LAN example. Commands are provided in individual black terminal boxes with white text and a Copy button for convenient use.

What you will build
  • One Ubuntu system acting as the NFS server.
  • One Ubuntu system acting as the NFS client.
  • A shared directory at /srv/nfs/shared.
  • Network access restricted to a specific LAN subnet.
  • A persistent mount configured on the client.

1. Understand the NFS Lab Topology

For this example, both machines are on the same private network. Replace the example IP addresses and subnet with values that match your own environment.

ComponentExample valuePurpose
NFS server192.168.1.10Stores and exports shared files.
NFS client192.168.1.20Mounts and accesses the shared directory.
LAN subnet192.168.1.0/24Permitted client network.
Export directory/srv/nfs/sharedDirectory shared by the server.
Client mount point/mnt/nfs/sharedLocal path used to access the share.
Important: These are example addresses, not your actual server addresses. Use static addresses or DHCP reservations for reliable server access. The subnet restriction is not a replacement for proper network segmentation and firewall rules.

2. Prepare Both Ubuntu Machines

Run the following commands on both the server and client. Updating package metadata ensures that APT can retrieve the current package information configured for your Ubuntu installation.

Run on both systems · Bash
sudo apt update
sudo apt upgrade -y

Check the Ubuntu release and network addresses on each system.

Run on both systems · Bash
lsb_release -a
ip -br address

Confirm that the machines can communicate. From the client, test the server’s IP address.

Run on the client · Bash
ping -c 4 192.168.1.10

If the ping fails, check the IP configuration, routing, VLANs, and firewall rules before continuing. A server may also block ICMP while still allowing NFS, so a failed ping alone does not prove that NFS is unavailable.

3. Install the NFS Server Package

On the Ubuntu machine that will store the shared files, install nfs-kernel-server. This package provides the NFS server components.

Run on the NFS server · Bash
sudo apt install nfs-kernel-server -y

Enable and start the service, then verify its status.

Run on the NFS server · Bash
sudo systemctl enable --now nfs-kernel-server
sudo systemctl status nfs-kernel-server --no-pager

The status output should indicate that the service is active. If it fails, inspect the service logs before configuring exports.

Run on the NFS server · Bash
sudo journalctl -u nfs-kernel-server -n 50 --no-pager

4. Create the Shared Directory

Create a dedicated directory for the NFS share instead of exporting an entire filesystem or a sensitive system directory. This example uses /srv/nfs/shared.

Run on the NFS server · Bash
sudo mkdir -p /srv/nfs/shared
sudo chown root:root /srv/nfs/shared
sudo chmod 755 /srv/nfs/shared

These initial permissions allow users to list and read files according to normal filesystem permissions, but do not give ordinary users write access to the directory. A later section configures a shared group for controlled write access.

5. Configure the NFS Export

The /etc/exports file determines which directories can be shared, which client addresses are allowed, and which access options apply. Open the file on the NFS server.

Run on the NFS server · Bash
sudo nano /etc/exports

Add the following line to the file:

/etc/exports · Configuration
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check,root_squash)

Save the file and exit the editor. The options mean:

OptionMeaning
rwAllows read and write requests, subject to normal filesystem permissions.
syncReplies to clients after changes have been committed to stable storage according to NFS semantics.
no_subtree_checkDisables subtree verification for this export.
root_squashMaps client root access to an unprivileged identity instead of granting server-root privileges.
Security: Keep root_squash enabled for a normal shared directory. Do not add no_root_squash just to fix permission problems. The client subnet must match your actual LAN, and NFS should not be exposed directly to the public internet.

Apply the export configuration and verify what the server is exporting.

Run on the NFS server · Bash
sudo exportfs -rav
sudo exportfs -v

6. Configure the Server Firewall

If UFW is enabled, allow TCP port 2049 only from the trusted LAN subnet used in this example. This tutorial uses NFSv4, which normally uses TCP port 2049 for client access.

Run on the NFS server · Bash
sudo ufw allow from 192.168.1.0/24 to any port 2049 proto tcp
sudo ufw status verbose

If UFW is inactive, the allow rule alone does not enable it. Before enabling UFW on a remote server, make sure SSH access is permitted so that you do not lock yourself out. If your network uses another firewall, apply an equivalent restriction there.

7. Install NFS Client Utilities

On the second Ubuntu machine, install nfs-common. It provides the NFS client utilities required to mount remote exports.

Run on the NFS client · Bash
sudo apt update
sudo apt install nfs-common -y

8. Create the Client Mount Point

Create an empty local directory where the remote NFS share will appear. Any existing files beneath a mount point become hidden while the remote filesystem is mounted, so choose an appropriate directory.

Run on the NFS client · Bash
sudo mkdir -p /mnt/nfs/shared

9. Mount the NFS Share

Mount the exported directory using the server IP address and the client mount point.

Run on the NFS client · Bash
sudo mount -t nfs -o vers=4 192.168.1.10:/srv/nfs/shared /mnt/nfs/shared

If the command completes without an error, verify the mount and the negotiated NFS version.

Run on the NFS client · Bash
findmnt /mnt/nfs/shared
nfsstat -m

Look for the server address, exported path, and NFS mount options in the output. If the mount fails, use the troubleshooting section below.

10. Test File Access

First, test basic access by listing the mounted directory.

Run on the NFS client · Bash
ls -la /mnt/nfs/shared

To test write access safely, configure a shared group on both machines. NFS commonly uses numeric user and group IDs for filesystem permission checks. Matching the relevant IDs between server and client is important.

10.1 Create a shared group on the server

On the server, create a group with GID 2000. If that GID is already in use, choose an unused GID and use the same number on both machines.

Run on the NFS server · Bash
getent group 2000 || sudo groupadd --gid 2000 nfsusers
sudo chown root:2000 /srv/nfs/shared
sudo chmod 2770 /srv/nfs/shared

The setgid bit on the directory helps new files and subdirectories inherit the shared group. These permissions allow group members to write, but do not grant access to everyone.

10.2 Create the same group on the client

Run on the NFS client · Bash
getent group 2000 || sudo groupadd --gid 2000 nfsusers
sudo usermod -aG nfsusers "$USER"

Log out and log back in on the client so the new group membership is applied. Confirm it with:

Run on the NFS client · Bash
id
touch /mnt/nfs/shared/client-test.txt
ls -l /mnt/nfs/shared/client-test.txt

If the write test succeeds, the client has the required directory permissions. If it fails, confirm that the mount is active, the user belongs to GID 2000, and the server directory has the intended group and permissions. Avoid broad permission changes such as chmod 777 as a troubleshooting shortcut.

11. Mount the Share Automatically at Boot

To make the NFS share persistent across reboots, add an entry to the client’s /etc/fstab. First, back up the current file.

Run on the NFS client · Bash
sudo cp /etc/fstab /etc/fstab.backup

Open the file:

Run on the NFS client · Bash
sudo nano /etc/fstab

Add this entry on a single line:

/etc/fstab · Configuration
192.168.1.10:/srv/nfs/shared /mnt/nfs/shared nfs defaults,_netdev,nofail,x-systemd.automount 0 0

The options tell systemd that the mount depends on networking, should not by itself prevent boot from continuing if the server is unavailable, and can be mounted on demand. For critical application data, evaluate whether nofail is appropriate for your service’s startup requirements.

Reload systemd and test the entry before rebooting.

Run on the NFS client · Bash
sudo systemctl daemon-reload
sudo mount -a
ls -la /mnt/nfs/shared
findmnt /mnt/nfs/shared

Resolve any errors before restarting the machine. A malformed /etc/fstab entry can cause mount failures during startup.

12. Verify the NFS Server and Export

If you need to confirm the server’s exported directories, run these commands on the server.

Run on the NFS server · Bash
sudo systemctl is-active nfs-kernel-server
sudo exportfs -v
sudo ss -lnt | grep ':2049'

On the client, confirm that the mount is present and inspect the filesystem usage.

Run on the NFS client · Bash
findmnt -t nfs,nfs4
df -h /mnt/nfs/shared

13. Troubleshooting Common NFS Problems

ProblemPossible causeWhat to check
Connection timed out Firewall, routing, or server availability Check server IP, TCP 2049, routing, and firewall rules.
Access denied by server Client address is outside the export rule or export configuration is incorrect Review /etc/exports and sudo exportfs -v.
Permission denied when writing UID/GID mismatch or insufficient directory permissions Check id, ownership, group membership, and directory mode.
Mount command fails Missing client package, incorrect export path, or unavailable server Verify nfs-common, the exported path, and server logs.
Share not mounted after reboot Incorrect fstab entry or mount dependencies Run sudo mount -a and inspect systemd mount logs.

Refresh the exports after correcting the server configuration:

Run on the NFS server · Bash
sudo exportfs -rav
sudo exportfs -v

For detailed service diagnostics, inspect the server logs:

Run on the NFS server · Bash
sudo journalctl -u nfs-server -u nfs-kernel-server -n 100 --no-pager

For further help, consult the official Ubuntu Server NFS guide and the Ubuntu manual pages.

14. Best Practices for a Production NFS Deployment

  • Use stable server addresses and restrict exports to trusted clients or subnets.
  • Keep the server updated and monitor service health and storage capacity.
  • Use normal filesystem permissions and matching numeric user/group IDs.
  • Keep root_squash enabled unless a carefully reviewed requirement justifies another configuration.
  • Do not expose NFS directly to the public internet.
  • Back up the underlying shared data independently of the NFS service.
  • For environments requiring stronger authentication or confidentiality, evaluate NFS with Kerberos and the appropriate security configuration.
  • Test persistent mounts and recovery behavior before putting dependent applications into production.

Related Articles on VMoreCloud

Verify these category links on the live website and replace any unavailable destination with a relevant published article.

Official Sources and Further Reading

About the Author

Khurram Shahzad — Hybrid Cloud & Virtualization Engineer

Hybrid Cloud & Virtualization Engineer specializing in VMware, Azure, AWS, Windows Server, Microsoft 365, Linux, networking, backup & disaster recovery. I share practical guides, technical projects and insights into modern IT infrastructure through VMoreCloud.

Explore more on VMoreCloud

Editorial note: This tutorial is based on Ubuntu’s published NFS documentation and a representative two-machine configuration. IP addresses are examples. Validate the configuration against your own network before using it in production.

Leave a Reply

Your email address will not be published. Required fields are marked *