Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install and Configure an NFS Server on Ubuntu

Share a folder over the network with NFS and mount it on another Linux machine.

VPS and Cloud Servers2 min read11 screenshots

What NFS is

NFS (Network File System) lets one computer share a folder, and other computers use it as if it were on their own disk. People use it for shared storage, teamwork on files, central file management and easy growth of storage.

On the server

Update the system and install the NFS server

sudo apt update && sudo apt upgrade -y
Updating the system
sudo apt install nfs-kernel-server
Installing the NFS server

Create the shared folder

sudo mkdir -p /var/nfs/share
Creating the shared folder

-p makes the parent folders too, and does not complain if the folder exists.

Set the owner and permissions

sudo chown nobody:nogroup /var/nfs/share
sudo chmod 755 /var/nfs/share
Setting the owner

(The original steps used chmod 777. That lets everyone write. Use 755 or a group-based setup unless you really need open access.)

Set the exports

Open the exports file:

sudo nano /etc/exports
Opening /etc/exports

Add one line. Replace the network with your own (or the IP address of the client):

/var/nfs/share 192.168.1.0/24(rw,sync,no_subtree_check)
The export line
  • rw allows reading and writing.
  • sync writes changes to disk before it answers.
  • no_subtree_check avoids some checks that slow down the server.

Apply the exports

sudo exportfs -a
Exporting the shares

Start and enable the service

sudo systemctl start nfs-server
sudo systemctl enable nfs-server
sudo systemctl status nfs-server
The NFS server status
  • start runs it now, enable runs it at boot, status shows if it works.

Open the firewall

Allow NFS only from your network:

sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw enable
sudo ufw status
Allowing NFS in the firewall

On the client

Install the NFS client:

sudo apt install nfs-common
Installing nfs-common

Mount the share (replace server_IP):

sudo mount server_IP:/var/nfs/share /mnt

To mount it at boot, add a line to /etc/fstab:

echo 'server_IP:/var/nfs/share /mnt nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0' | sudo tee -a /etc/fstab
The mount line in fstab

Test it by writing a file in /mnt on the client and looking for it in /var/nfs/share on the server.

Why use NFS

  • Collaboration. Teams share files on one place.
  • Central management. One place to back up and control.
  • Scalability. Add storage without changing the clients.
  • Convenience. No manual copying between machines.

Quick recap

  • Install nfs-kernel-server, create a folder and add it to /etc/exports.
  • Run exportfs -a and open the firewall for your network.
  • Mount it on clients with mount server_IP:/path /mnt.