UBUNTU SERVER · LINUX NETWORKING · STEP-BY-STEP TUTORIAL
How to Set Up an NFS Server and Client on Ubuntu 26.04.2
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.
- 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.
| Component | Example value | Purpose |
|---|---|---|
| NFS server | 192.168.1.10 | Stores and exports shared files. |
| NFS client | 192.168.1.20 | Mounts and accesses the shared directory. |
| LAN subnet | 192.168.1.0/24 | Permitted client network. |
| Export directory | /srv/nfs/shared | Directory shared by the server. |
| Client mount point | /mnt/nfs/shared | Local path used to access the share. |
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.
sudo apt update
sudo apt upgrade -y
Check the Ubuntu release and network addresses on each system.
lsb_release -a
ip -br address
Confirm that the machines can communicate. From the client, test the server’s IP address.
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.
sudo apt install nfs-kernel-server -y
Enable and start the service, then verify its status.
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.
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.
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.
sudo nano /etc/exports
Add the following line to the file:
/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:
| Option | Meaning |
|---|---|
rw | Allows read and write requests, subject to normal filesystem permissions. |
sync | Replies to clients after changes have been committed to stable storage according to NFS semantics. |
no_subtree_check | Disables subtree verification for this export. |
root_squash | Maps client root access to an unprivileged identity instead of granting server-root privileges. |
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.
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.
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.
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.
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.
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.
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.
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.
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
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:
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.
sudo cp /etc/fstab /etc/fstab.backup
Open the file:
sudo nano /etc/fstab
Add this entry on a single line:
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.
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.
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.
findmnt -t nfs,nfs4
df -h /mnt/nfs/shared
13. Troubleshooting Common NFS Problems
| Problem | Possible cause | What 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:
sudo exportfs -rav
sudo exportfs -v
For detailed service diagnostics, inspect the server logs:
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_squashenabled 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
- Linux tutorials and news — Explore Linux administration, distributions, and command-line guides.
- Networking tutorials — Browse network configuration and infrastructure topics.
- Virtualization guides — Learn about virtual machines and infrastructure services.
- Cloud computing articles — Explore cloud infrastructure and administration.
Verify these category links on the live website and replace any unavailable destination with a relevant published article.
Official Sources and Further Reading
- Ubuntu Server documentation: Network File System (NFS)
- Ubuntu Server: NFS overview and advanced configuration
- Ubuntu 26.04 LTS release notes
- Ubuntu manual: exports(5)
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.
