Ubuntu NFS Mount Tutorial: A Complete Step-by-Step Setup Guide
10:34, 20.08.2026
What Is NFS and Why Use It on Ubuntu?
The Network File System (NFS) is a protocol that allows you to share directories and files between Linux systems over a network. NFS is particularly useful when you need centralized file storage accessible from multiple machines, common in enterprise environments, development clusters, or home labs. With native support in Ubuntu, NFS offers a lightweight, fast, and easy-to-configure way to manage network file sharing.
Understanding the Client-Server Model in NFS
NFS works on a client-server architecture. The server exports (shares) directories, and the client mounts these directories locally, interacting with them as if they were part of the local file system. This design makes NFS ideal for distributed computing environments, such as compute clusters or Docker-based CI/CD pipelines.
How to Set Up an NFS Server on Ubuntu (Installation & Configuration)
Step 1: Install the NFS Server on Ubuntu
To begin, install the NFS kernel server package:
sudo apt update sudo apt install nfs-kernel-server
This will install the necessary daemons to share directories via NFS.
Client-Side Setup
On the client machine(s), install the NFS client utilities:
sudo apt update sudo apt install nfs-common
Step 2: Create and Configure Shared Directories on the Host
Let’s say you want to share /mnt/shared. First, create the directory and set proper ownership:
sudo mkdir -p /mnt/shared sudo chown nobody:nogroup /mnt/shared
You can adjust permissions based on your use case, e.g., for multi-user write access.
Step 3: Grant Access to Client Machines
Edit the /etc/exports file to define which clients can access which directories:
/mnt/shared 192.168.1.0/24(rw,sync,no_subtree_check)
This allows the entire 192.168.1.x subnet to mount the directory with read/write permissions.
Step 4: Export the Shared Directory via NFS
After editing /etc/exports, reload the export table:
sudo exportfs -a
Ensure the NFS service is enabled and running:
sudo systemctl enable nfs-server sudo systemctl start nfs-server
Step 5: Open Firewall Access for NFS Traffic
Use UFW or iptables to allow NFS-related ports (2049 for NFSv4):
sudo ufw allow from 192.168.1.0/24 to any port nfs sudo ufw reload
Troubleshooting Common NFS Mount Issues
1. Unable to Access Files on a Mounted NFS Share
Make sure the NFS share directory has proper permissions. If it’s owned by nobody:nogroup, adjust as needed using chown or ACLs for finer control.
2. Mounting the NFS Share Fails
Ensure the server is reachable, and the directory is exported. Try:
sudo showmount -e <nfs-server-ip>
Error: Permission Denied from Server
Double-check the subnet or IP permissions in /etc/exports. A mismatch will result in "Permission Denied."
3. NFS Performance Bottlenecks and How to Fix Them
Performance can degrade due to sync mode. Use async for speed, but only if you can tolerate some risk of data loss in case of a crash. Consider tuning mount options like rsize, wsize, and using NFSv4 for better performance and fewer open ports.
Best Practices for a Reliable NFS Setup
For a reliable NFS setup, you can practice the following principles:
- Use static IPs or DNS entries for all clients in /etc/exports.
- Prefer NFSv4 for better security and reduced port usage.
- Secure your setup with firewall rules and user access controls.
- Monitor your NFS server with tools like nfsstat and iotop.
- Avoid exporting directories with high permission complexity (e.g., /home) unless you manage user ID consistency across nodes.
FAQ
How do I check if NFS is installed on Ubuntu?
Run dpkg -l | grep nfs or check services with systemctl status nfs-server.
Can I mount an NFS share on a Windows machine?
Yes, Windows 10 Pro and higher support NFS client features via the "Services for NFS" optional feature.
Why is my NFS mount read-only on Ubuntu?
Check the ro flag in /etc/exports and verify client mount options don’t enforce read-only.
How do I restart the NFS service on Ubuntu?
Use: sudo systemctl restart nfs-server.
How do I force an NFS unmount?
Run: sudo umount -f /mount/point.
Does NFS support encryption?
Not natively. For secure transport, use NFS over a VPN or configure it with Kerberos (NFSv4 with sec=krb5p).
How can I view active NFS connections?
Use ss -tulpn | grep nfs, netstat, or check with nfsstat and /var/log/syslog.