Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Ubuntu 26.04 Resolute Raccoon |
| Software | nfs-kernel-server, nfs-common (1:2.8.3-1) |
| Other | Privileged 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.
| Step | Command/Action |
|---|---|
| 1. Install NFS server | sudo apt install nfs-kernel-server |
| 2. Export a directory | echo '/srv/nfs 192.168.178.0/24(rw,sync,no_subtree_check)' | sudo tee -a /etc/exports && sudo exportfs -ra |
| 3. Mount from client | sudo apt install nfs-common && sudo mount 192.168.178.79:/srv/nfs /mnt/nfs |
| 4. Make persistent | Add entry to /etc/fstab |
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.
IMPORTANT
The IP addresses used in this tutorial (192.168.178.79 for the server and 192.168.178.72 for the client) are examples only. Replace them with the actual IP addresses of your own machines. You can find your current IP address by running ip a.
For reliable results, it is advisable to assign a static IP to your NFS server so the address does not change between reboots.
This section covers installing the NFS server packages, creating a shared directory, and configuring the exports file on your Ubuntu 26.04 server machine.
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/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/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 exported192.168.178.0/24 – allows any host on the 192.168.178.x subnet to connectrw – grants read and write accesssync – ensures data is written to disk before confirming the operation, improving reliabilityno_subtree_check – disables subtree checking for better performance and reliability/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.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:
$ sudo ufw allow from 192.168.178.0/24 to any port nfs
Alternatively, you can specify the port number directly:
$ sudo ufw allow from 192.168.178.0/24 to any port 2049
Verify the firewall rules: Confirm that the new rule is in place:
$ sudo ufw status
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.
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.
nfs-common:$ sudo apt update $ sudo apt install nfs-commonshowmount command to query the server:$ sudo showmount -e 192.168.178.79The output should list /srv/nfs along with the allowed client range.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.
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.
/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 typedefaults – 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 mountmount -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.IMPORTANT
If the NFS server is unavailable during client boot, the _netdev option prevents the system from hanging indefinitely. However, the mount point will remain empty until the server becomes reachable. You can add the bg option (e.g., nfs defaults,_netdev,bg 0 0) to retry the mount in the background.
Even with a correct setup, NFS occasionally presents problems. Below are the most common issues and their solutions.
If the client reports “Permission denied” when accessing the mount, check the following:
/etc/exports entry on the server includes the client’s IP or subnet.sudo exportfs -rals -ld /srv/nfsA mount command that hangs typically points to a network or firewall issue. Use the following to diagnose:
$ rpcinfo -p 192.168.178.79
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:
$ nc -zv 192.168.178.79 2049
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:
$ sudo umount -f /mnt/nfs
$ sudo mount 192.168.178.79:/srv/nfs /mnt/nfs
If a regular unmount fails, force it with -l (lazy unmount):
$ sudo umount -l /mnt/nfs
The following commands are helpful when tracking down NFS problems:
| Command | Purpose |
|---|---|
sudo showmount -e 192.168.178.79 | Lists all exports from the server |
exportfs -v | Shows currently active exports with options (run on server) |
rpcinfo -p 192.168.178.79 | Lists RPC services registered on the server |
nfsstat -c | Displays NFS client-side statistics |
nfsstat -s | Displays NFS server-side statistics |
mount | grep nfs | Shows currently mounted NFS filesystems |
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.