NFS (Network File System) allows Linux servers to share directories over the network. Client machines mount NFS shares and access files as if they were local. This guide configures an NFS server and client on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Two Ubuntu 24.04 LTS servers (server and client) on the same network
- A user with sudo privileges on both
Step 1 – Install NFS Server
On the NFS server:
sudo apt update
sudo apt install nfs-kernel-server -y
Step 2 – Create and Configure the Share Directory
Create the directory to share:
sudo mkdir -p /mnt/nfsshare
sudo chown -R nobody:nogroup /mnt/nfsshare
sudo chmod 755 /mnt/nfsshare
Step 3 – Export the Directory
Edit the NFS exports file:
sudo nano /etc/exports
Add:
/mnt/nfsshare 192.168.1.0/24(rw,sync,no_subtree_check)
Apply the configuration:
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
Step 4 – Allow NFS Through the Firewall
Allow NFS traffic:
sudo ufw allow from 192.168.1.0/24 to any port nfs
Step 5 – Install NFS Client
On the NFS client server:
sudo apt install nfs-common -y
Step 6 – Mount the NFS Share
Mount the remote share:
sudo mkdir -p /mnt/nfsdata
sudo mount server_ip:/mnt/nfsshare /mnt/nfsdata
Step 7 – Make the Mount Persistent
Add to /etc/fstab on the client:
echo 'server_ip:/mnt/nfsshare /mnt/nfsdata nfs defaults 0 0' | sudo tee -a /etc/fstab
Conclusion
NFS file sharing is now configured between Ubuntu 24.04 LTS servers. NFS is ideal for sharing media libraries, home directories, and build artifacts across a local network.