Background & Why You Should Use NFS for Your Local Network?
Are you managing a cluster of 3-5 Linux servers or simply want to turn an old Ubuntu PC into a shared drive for your home? File sharing becomes crucial in these scenarios. Previously, I spent quite some time struggling with Samba. However, if you’re working purely in a Linux-to-Linux environment, NFS (Network File System) is truly the “match made in heaven”.
NFS is lightweight and offers impressive access speeds. In fact, on a 1Gbps network, I usually achieve a stable copy speed of around 112MB/s, nearing the physical limit of the cable. More importantly, it preserves Linux permissions. I’ve deployed NFS for cluster projects to sync source code and logs between nodes. The result? The system runs extremely smoothly with no significant latency.
Installing NFS Kernel Server on Ubuntu
Forget about manual downloads. On Ubuntu, everything you need is available in the official repositories. It only takes a few seconds. First, update your system for a smooth installation:
sudo apt update
sudo apt upgrade -y
Next, install the nfs-kernel-server package. This is the core component that turns your Ubuntu machine into a data sharing “hub”.
sudo apt install nfs-kernel-server -y
The NFS service will start automatically after installation. However, don’t rush to connect just yet. We need to prepare the storage directory and set the permissions correctly first.
Detailed Configuration: From Directory Creation to Permissions
This section is where errors are most likely to occur. Many people complete the configuration but still encounter Permission denied errors because of incorrect permissions.
1. Creating the Shared Directory
My experience is to create the directory in /mnt for centralized management. For example, I’ll create a folder named nfs_share.
sudo mkdir -p /mnt/nfs_share
2. Directory Permissions
NFS manages permissions based on UID and GID. To make it quick and simple, I’ll assign this directory to the nobody user and nogroup group. This approach allows all clients to write data without running into user identification issues between the two machines.
sudo chown nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
3. Configuring the Exports File
Open the /etc/exports file to declare which directory will be shared. Use nano for speed:
sudo nano /etc/exports
Add the following line to the end of the file. Don’t forget to replace 192.168.1.0/24 with your actual network IP range:
/mnt/nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)
Let’s review some important parameters so you aren’t just blindly copy-pasting:
- rw: Allows clients to read and write data freely.
- sync: The server only confirms once data is safely on the disk. Slightly slower but safer, preventing data loss during sudden power outages.
- no_subtree_check: Speeds up access by skipping subdirectory tree checks.
Save the file. Finally, run the following command for the server to recognize the new configuration:
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
4. Opening the Firewall (UFW)
If the server has a firewall enabled, you need to open the port so clients can “enter”.
sudo ufw allow from 192.168.1.0/24 to any port nfs
Type sudo ufw status to ensure that the NFS port is in the ALLOW state.
Connecting from a Client Machine and Setting up Auto-Mount
Switch to the client machine (the one that wants to use the files). You’ll also need a small tool to communicate with the NFS Server:
sudo apt update
sudo apt install nfs-common -y
Create an empty directory as a connection point on the client machine:
sudo mkdir -p /home/user/data_shared
Try connecting manually to see if everything is working. Remember to use the correct server IP:
sudo mount 192.168.1.10:/mnt/nfs_share /home/user/data_shared
Connected? Try creating a small text file to see if it appears on the server side. If everything looks good, we should configure the machine to auto-mount on every reboot. No one wants to type the mount command every day.
Open the system configuration file /etc/fstab:
sudo nano /etc/fstab
Add this line to the very end:
192.168.1.10:/mnt/nfs_share /home/user/data_shared nfs defaults,user,exec,_netdev 0 0
A small but vital tip: the _netdev parameter is extremely important. It forces the system to wait for the network to be ready before mounting, preventing the machine from hanging (boot loop) during startup.
Monitoring & Testing the System
Configuration is done; now it’s time to check the results. On the server, use this command to see the list of currently shared directories:
sudo exportfs -v
To monitor performance and active connections, use the nfsstat command:
nfsstat -s
If the copy speed is slow, check your network cables or switch. In my experience, if you’re on a 1Gbps network but the speed is only around 10-20MB/s, it’s likely that your network card or hard drive is a bottleneck.
One last tip: type mount | grep nfs on the client machine to see the details of the options the system is using. Hopefully, this guide helps you confidently deploy your own centralized storage system!

