
How to Set Up an NFS Server on Ubuntu 24.04 LTS (Step-by-Step Guide)
Network File System (NFS) is a distributed file-sharing protocol that allows users to access and share files and directories over a network as if they were stored locally. It operates on a client-server model, where the NFS server exports shared directories, and multiple clients can mount them for seamless access. NFS is widely used in Linux environments to enable efficient resource sharing between systems. It’s especially valuable in cloud-based setups, as it helps reduce storage costs and optimize space by centralizing data on a single server.
In this guide, you’ll learn how to set up an NFS server on Ubuntu 24.04 LTS. The steps provided are also compatible with other Ubuntu-based or Linux distributions, making it a versatile solution for file sharing across multiple systems.
Prerequisites
Before getting started, ensure you have:
1. A server running Ubuntu 24.04 LTS with a static IP and root access.
2. A client system running Ubuntu with sudo privileges.
Step 1: Update the System
Begin by updating your system packages to ensure you’re working with the latest security patches and features.
sudo apt update -y && sudo apt upgrade -yStep 2: Install and configure the NFS Server
On your server system, install the NFS server package:
sudo apt install nfs-kernel-server -yStart the NFS service, enable it to launch at system boot, and verify its status using the following commands:
sudo systemctl start nfs-server.servicesudo systemctl enable nfs-server.servicesudo systemctl status nfs-server.serviceOutput:
sohan@nfs-server:~# sudo systemctl status nfs-server.service
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; preset: enabled)
Active: active (exited) since Fri 2025-04-18 15:31:44 UTC; 2min ago
Main PID: 2154 (code=exited, status=0/SUCCESS)
CPU: 18ms
Step 3: Create and Configure the NFS Shared Directory
Next, create a shared directory on the NFS server that will be accessible from the client machine. Use the following command to create it:
sudo mkdir -p /mnt/nfsshareCreate test files:
sudo touch /mnt/nfsshare/file1.txtsudo touch /mnt/nfsshare/file2.txtSet proper ownership and permissions:
sudo chown -R nobody:nogroup /mnt/nfsshare/sudo chmod 777 /mnt/nfsshare/Step 4: Define NFS Export Rules
Now, open the NFS server configuration file and specify the directory you want to share. Use the following command to edit the file:
sudo vim /etc/exportsAdd the following line (replace with your client’s IP address):
/mnt/nfsshare 192.168.1.51(rw,sync,no_subtree_check)To allow multiple clients, add separate lines for each IP.
/mnt/nfsshare 192.168.1.51(rw,sync,no_subtree_check)
/mnt/nfsshare 192.168.1.52(rw,sync,no_subtree_check)Explanation of options:
rw: Grants read/write access.
- Sync: Ensures changes are committed to disk before replying.
- no_subtree_check: Prevents subtree checks for improved performance.
Export the shared directory:
sudo exportfs -aTo apply the changes, restart the NFS service:
sudo systemctl restart nfs-kernel-serverStep 5: Install and Configure NFS Client
On the client machine, install the NFS client utilities:
sudo sudo apt update -y && sudo apt install nfs-common -yStart and enable the NFS client service:
sudo systemctl start nfs-client.targetsudo systemctl enable nfs-client.targetVerify the NFS server’s exported directory from the client:
showmount -e <NFS_SERVER_IP>Make sure to replace the IP address with the actual IP address of your NFS server.
showmount -e 192.168.1.21Output:
sohan@nfs-client:~$ showmount -e 192.168.1.21
Export list for 192.168.1.21:
/mnt/nfsshare 192.168.1.51
sohan@nfs-client:~$
Step 6: Mount the NFS Share on the Client
Create a mount point on the client:
sudo mkdir -p /mnt/nfs_share_mountThen, mount the shared directory from the NFS server on the NFS client using the following command:
sudo mount 192.168.1.21:/mnt/nfsshare /mnt/nfs_share_mountHere, replace the IP address with your NFS server IP address.
To mount the NFS share automatically on boot, edit /etc/fstab:
sudo vim /etc/fstabNext, add the following line, replacing it with your NFS server’s IP address and the NFS directory name:
192.168.1.21:/mnt/nfsshare /mnt/nfs_share_mount nfs defaults 0 0Now, the NFS file system will be automatically mounted every time the system reboots.
Step 7: Verify the NFS share on the client system
Use the df -h Command to verify the mounted directory:
df -hOutput:
sohan@nfs-client:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 46M 1.1M 45M 3% /run
/dev/vda1 8.7G 1.4G 7.3G 16% /
tmpfs 230M 0 230M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/vda16 881M 61M 758M 8% /boot
/dev/vda15 105M 6.1M 99M 6% /boot/efi
192.168.1.21:/mnt/nfsshare 8.7G 1.4G 7.3G 16% /mnt/nfs_share_mount
tmpfs 46M 12K 46M 1% /run/user/0
sohan@nfs-client:~$
The mount point will show your server’s IP address, followed by the shared directory path, as highlighted in the output above.
Now, test file creation from the client:
touch /mnt/nfs_share_mount/file3Here, we created file3 on the NFS client. Now, log in to the NFS server and check the NFS directory.
ll /mnt/nfsshare/Output:
sohan@nfs-server:~$ ll /mnt/nfsshare/
total 8
drwxrwxrwx 2 nobody nogroup 4096 April 10 15:40 ./
drwxr-xr-x 3 root root 4096 April 10 13:51 ../
-rw-r--r-- 1 nobody nogroup 0 April 10 13:53 file1.txt
-rw-r--r-- 1 nobody nogroup 0 April 10 13:54 file2.txt
-rw-rw-r-- 1 sohan sohan 0 April 10 15:40 file3
sohan@nfs-server:~$
You should see file3 created by the client.
Conclusion
You’ve successfully set up an NFS server on Ubuntu 24.04 LTS and connected to it from a client machine. You can now share files seamlessly across Linux systems. If you have any questions or run into issues, feel free to ask!