Table of Contents
NFS (Network File System) allows you to share directories and files between Linux systems over a network. Setting up an NFS server on Ubuntu 24.04 enables multiple clients to access shared folders efficiently, making it ideal for centralized storage or collaborative environments.
STEP 1: Update Your System
Before installing NFS, ensure your system packages are up to date. This prevents compatibility issues and ensures the latest features are available.
sudo apt update
sudo apt upgrade -y
STEP 2: Install NFS Server
To share files over the network, you need the NFS server package installed on Ubuntu 24.04. Installing it ensures your system can host shared directories and respond to client requests reliably.
sudo apt install nfs-kernel-server -y
Check the service status:
sudo systemctl status nfs-server
STEP 3: Create a Directory to Share
Choose or create the directory you want to share over the network. For example:chmod 777 allows full access. Adjust permissions according to your security requirements
sudo mkdir -p /srv/nfs/shared
Set proper permissions:
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 777 /srv/nfs/shared
STEP 4: Configure NFS Exports
Edit the /etc/exports file to define which clients can access the shared directory and their permissions:
sudo nano /etc/exports
Add the following line:
srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)
STEP 5: Export the Shared Directory
After configuring the NFS exports, you need to apply the settings so the server makes the directory available to clients. Exporting ensures the shared folder is recognized by the NFS service.
sudo exportfs -a
Check which directories are exported:
sudo exportfs -v
STEP 6: Start and Enable NFS Server
To make the shared directory accessible to clients, the NFS service must be running. Enabling it ensures that the server automatically starts the NFS service after every system reboot.
sudo systemctl restart nfs-server
sudo systemctl enable nfs-server
STEP 7: Allow NFS Through Firewall
If your Ubuntu server uses a firewall, you need to allow NFS traffic so clients on the network can connect to the shared directory securely without being blocked.
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw reload
STEP 8: Mount NFS Share on Client
To access the shared folder from a client machine, you must mount the NFS share. This step connects the client to the server, allowing read and write operations as if the folder were local.
sudo mkdir -p /mnt/nfs/shared
sudo mount 192.168.1.10:/srv/nfs/shared /mnt/nfs/shared
To mount automatically at boot, add this line to:
192.168.1.10:/srv/nfs/shared /mnt/nfs/shared nfs defaults 0 0
STEP 9: Test NFS Share
After mounting the NFS share on the client, it’s important to verify that the connection works correctly. Testing ensures that files can be created, read, and modified without errors.
cd /mnt/nfs/shared
touch testfile
ls -l