Friday, April 17, 2026
Linux

How to Set Up NFS Server and Client on Ubuntu 26.04

51views

NFS (Network File System) allows you to share directories and files across a network, making remote storage accessible as if it were local. In this guide, we walk through how to set up an NFS server and client on Ubuntu 26.04, covering everything from installation and exports configuration to client mounting, fstab automation, and firewall rules.

Software Requirements

CategoryRequirements, Conventions or Software Version Used
SystemUbuntu 26.04 Resolute Raccoon
Softwarenfs-kernel-server, nfs-common (1:2.8.3-1)
OtherPrivileged access to your Linux system as root or via the sudo command. Two Ubuntu 26.04 machines on the same network (one server, one client).
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Set up NFS file sharing between two Ubuntu 26.04 machines by installing nfs-kernel-server on the server, defining exports, and mounting from the client with nfs-common.

StepCommand/Action
1. Install NFS serversudo apt install nfs-kernel-server
2. Export a directoryecho '/srv/nfs 192.168.178.0/24(rw,sync,no_subtree_check)' | sudo tee -a /etc/exports && sudo exportfs -ra
3. Mount from clientsudo apt install nfs-common && sudo mount 192.168.178.79:/srv/nfs /mnt/nfs
4. Make persistentAdd entry to /etc/fstab

Understanding NFS on Ubuntu 26.04

NFS, or Network File System, is a distributed file system protocol that lets you share directories over a network. A server “exports” one or more directories, and clients “mount” those exports to access files transparently. The result is that users on the client machine can read and write files on the remote server as though they were stored locally.

Ubuntu 26.04 ships with support for NFSv4 by default, which is the recommended version for most deployments. Compared to the older NFSv3, version 4 consolidates all traffic over a single TCP port (2049), simplifies firewall configuration, and adds built-in support for stronger authentication. Consequently, all examples in this tutorial use NFSv4 unless noted otherwise.

In our setup, we use two Ubuntu 26.04 machines on the same local network. Throughout this tutorial, we use the following example IP addresses: 192.168.178.79 for the NFS server and 192.168.178.72 for the client.

For reliable results, it is advisable to assign a static IP to your NFS server so the address does not change between reboots.

Installing the NFS Server on Ubuntu 26.04

This section covers installing the NFS server packages, creating a shared directory, and configuring the exports file on your Ubuntu 26.04 server machine.

  1. Update package lists and install the NFS server: Begin by refreshing your repositories and installing the nfs-kernel-server package, which provides the user-space NFS daemon and supporting utilities.$ sudo apt update $ sudo apt install nfs-kernel-serverAfter installation completes, the NFS server service starts automatically. You can verify its status at any time:$ sudo systemctl status nfs-server
  2. Create the shared directory: Next, create a directory that you want to share over the network. We use /srv/nfs as the export path, though you can choose any location.$ sudo mkdir -p /srv/nfsSet the ownership to nobody:nogroup so that all NFS clients can access the share regardless of their local user IDs. This is a common approach for general-purpose shared directories:$ sudo chown nobody:nogroup /srv/nfs $ sudo chmod 777 /srv/nfs
  3. Configure the exports file: The /etc/exports file defines which directories are shared, with whom, and under what permissions. Open it with your preferred text editor:$ sudo nano /etc/exportsAdd the following line at the end of the file:/srv/nfs 192.168.178.0/24(rw,sync,no_subtree_check)Here is what each option means:
    • /srv/nfs – the directory being exported
    • 192.168.178.0/24 – allows any host on the 192.168.178.x subnet to connect
    • rw – grants read and write access
    • sync – ensures data is written to disk before confirming the operation, improving reliability
    • no_subtree_check – disables subtree checking for better performance and reliability
    Save and close the file when you are done.
  4. Apply the exports: After editing /etc/exports, apply the changes by re-exporting all directories:$ sudo exportfs -raVerify that your export is active:$ sudo exportfs -vYou should see /srv/nfs listed along with the configured options.
  5. Create a test file in the shared directory: Place a simple file in the export directory so you can later confirm that the client can see it:$ echo “Hello from LinuxConfig.org” | sudo tee /srv/nfs/test.txt

Configuring the Firewall for NFS

If UFW (Uncomplicated Firewall) is active on your server, you must open port 2049 to allow NFS traffic. Since NFSv4 operates entirely over TCP port 2049, firewall configuration is straightforward. For a more detailed walkthrough on managing firewall rules, refer to the guide on how to ufw allow port on Ubuntu 26.04.

Allow NFS through UFW: Run the following command to permit NFS connections from your local subnet:

Alternatively, you can specify the port number directly:

Verify the firewall rules: Confirm that the new rule is in place:

You should see an entry allowing port 2049 from the 192.168.178.0/24 network.

    SECURITY ALERT
    Avoid using sudo ufw allow nfs without a source restriction. Opening NFS to all addresses exposes your shared files to any network your server can reach. Always restrict access to trusted subnets or specific IP addresses.

    Installing and Configuring the NFS Client on Ubuntu 26.04

    Now switch to the client machine (192.168.178.72). The NFS client needs only the nfs-common package, which provides the mount utilities for NFS shares.

    1. Install NFS client utilities: Update the package list and install nfs-common:$ sudo apt update $ sudo apt install nfs-common
    2. Verify available exports from the server: Before mounting, confirm what the server is sharing. Use the showmount command to query the server:$ sudo showmount -e 192.168.178.79The output should list /srv/nfs along with the allowed client range.
    3. Create a local mount point: Create a directory where the NFS share will be mounted on the client:$ sudo mkdir -p /mnt/nfs
    4. Mount the NFS share: Mount the remote directory to your local mount point:$ sudo mount 192.168.178.79:/srv/nfs /mnt/nfs
    5. Verify the mount: Confirm the NFS share is mounted and accessible:$ df -h /mnt/nfsYou should see the remote NFS share listed with its available and used space. Next, list the contents of the mount to confirm you can see the test file created on the server:$ ls -l /mnt/nfs/You should see test.txt in the listing. Finally, verify write access from the client by creating an additional file:$ touch /mnt/nfs/linuxconfig_client_test.txt $ ls -l /mnt/nfs/If both files appear in the listing, the NFS share is fully operational with read and write access.

    COMPLETED
    The NFS share is now mounted and operational. Files written to /mnt/nfs on the client are stored on the server at /srv/nfs.

    Automating NFS Mounts with fstab

    The manual mount command from the previous section does not survive a reboot. To make the NFS mount persistent, add an entry to /etc/fstab on the client machine. This ensures the share is mounted automatically every time the system starts.

    1. Open the fstab file: Edit /etc/fstab on the client:$ sudo nano /etc/fstabAdd the following line at the end:192.168.178.79:/srv/nfs /mnt/nfs nfs defaults,_netdev 0 0The key options here are:
      • nfs – specifies the filesystem type
      • defaults – applies standard mount options (rw, suid, dev, exec, auto, nouser, async)
      • _netdev – tells the system this mount depends on the network, so it waits until the network is available before attempting to mount
    2. Test the fstab entry without rebooting: First, unmount the existing manual mount, then use mount -a to process all fstab entries:$ sudo umount /mnt/nfs $ sudo mount -aVerify the mount is active again:$ df -h /mnt/nfsIf the share appears, the fstab entry is correct.
    3. Reboot and confirm persistence: For a final verification, reboot the client machine and check that the NFS share mounts automatically:$ sudo rebootAfter the system restarts, log in and run:$ df -h /mnt/nfs

    Troubleshooting Common NFS Issues on Ubuntu 26.04

    Even with a correct setup, NFS occasionally presents problems. Below are the most common issues and their solutions.

    Permission Denied Errors

    If the client reports “Permission denied” when accessing the mount, check the following:

    • Verify the /etc/exports entry on the server includes the client’s IP or subnet.
    • Re-export after any changes: sudo exportfs -ra
    • Confirm directory permissions on the server: ls -ld /srv/nfs

    Mount Hangs or Times Out

    A mount command that hangs typically points to a network or firewall issue. Use the following to diagnose:

    This shows whether NFS RPC services are reachable on the server. If the command fails, check that the NFS server is running and that port 2049 is open in the firewall.

    Additionally, you can test basic connectivity:

    Stale File Handle Errors

    A “Stale file handle” error occurs when the server-side export changes (for example, after the directory is deleted and recreated) while the client still holds a reference. To resolve this, unmount and remount the share:

    If a regular unmount fails, force it with -l (lazy unmount):

    Useful Diagnostic Commands

    The following commands are helpful when tracking down NFS problems:

    CommandPurpose
    sudo showmount -e 192.168.178.79Lists all exports from the server
    exportfs -vShows currently active exports with options (run on server)
    rpcinfo -p 192.168.178.79Lists RPC services registered on the server
    nfsstat -cDisplays NFS client-side statistics
    nfsstat -sDisplays NFS server-side statistics
    mount | grep nfsShows currently mounted NFS filesystems

    Conclusion

    You have successfully configured an NFS server and client on Ubuntu 26.04. The server exports a shared directory over the network, and the client mounts it for transparent file access. With the fstab entry in place, the mount persists across reboots, and with the firewall rules configured, only authorized hosts can connect. Moreover, the troubleshooting section gives you the tools to diagnose and resolve common issues quickly. NFS remains one of the most efficient and widely supported methods for sharing files between Linux systems, and it integrates naturally into any Ubuntu environment.

    Leave a Response