How to Set Up NFS Server and Client on Ubuntu 26.04
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
| 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 |
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.
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.
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.
- Update package lists and install the NFS server: Begin by refreshing your repositories and installing the
nfs-kernel-serverpackage, 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 - Create the shared directory: Next, create a directory that you want to share over the network. We use
/srv/nfsas the export path, though you can choose any location.$ sudo mkdir -p /srv/nfsSet the ownership tonobody:nogroupso 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 - Configure the exports file: The
/etc/exportsfile 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
- 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/nfslisted along with the configured options. - 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:
$ 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.
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.
- Install NFS client utilities: Update the package list and install
nfs-common:$ sudo apt update $ sudo apt install nfs-common - Verify available exports from the server: Before mounting, confirm what the server is sharing. Use the
showmountcommand to query the server:$ sudo showmount -e 192.168.178.79The output should list/srv/nfsalong with the allowed client range. - Create a local mount point: Create a directory where the NFS share will be mounted on the client:$ sudo mkdir -p /mnt/nfs
- Mount the NFS share: Mount the remote directory to your local mount point:$ sudo mount 192.168.178.79:/srv/nfs /mnt/nfs
- 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.txtin 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.
- Open the fstab file: Edit
/etc/fstabon 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 mount
- Test the fstab entry without rebooting: First, unmount the existing manual mount, then use
mount -ato 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. - 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
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.
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/exportsentry 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:
$ 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
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:
$ 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
Useful Diagnostic Commands
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 |
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.
Share this:
- Share on Facebook (Opens in new window) Facebook
- Share on X (Opens in new window) X
- Share on Bluesky (Opens in new window) Bluesky
- Share on LinkedIn (Opens in new window) LinkedIn
- Share on Reddit (Opens in new window) Reddit
- Share on Threads (Opens in new window) Threads
- Print (Opens in new window) Print
- Share on Mastodon (Opens in new window) Mastodon







