How to Set Up NFS Share on Ubuntu 22.04, 20.04

NFS stands for Network File System. This tutorial is going to show you how to configure NFS share on Ubuntu 20.04, 22.04 so that other computers in your local network can access files and directories on the Ubuntu 20.04, 22.04 system.

NFS allows directories and file systems to be shared across a local network. NFS can also be set up over the Internet with a VPN protocol to encrypt the connection. In this tutorial, we will set up NFS file share in a home network with two Ubuntu 20.04/22.04 computers.

Step 1: Configure the NFS Server

On the Ubuntu server, install the nfs-kernel-server packages.

sudo apt install nfs-kernel-server

Then edit the /etc/exports file with a command-line text editor such as Nano. The exports files tell NFS server which directories or file systems will be shared to client.

sudo nano /etc/exports

The syntax is as follows

/path/to/directory     client-IP address(options)

For example, you want to share your home directory to the second Ubuntu computer with IP address 192.168.1.101, then put the following line at the end of the file. Replace username with your actual username. Delimit the two columns with Tab key.

/home/username      192.168.1.101(rw,sync,root_squash,subtree_check)

ubuntu nfs share server

Press Ctrl+O to save the file, then CTRL+X to exit out of the file. The IP address of the client computer can be found by running the following command on the client side.

ifconfig

ifconfig find IP address on ubuntu

Reload the /etc/exports file.

sudo exportfs -ra

sudo systemctl restart nfs-server

Step 2: Configure the Client

On the second Ubuntu computer, install nfs-common package.

sudo apt install nfs-common

Then edit /etc/fstab file.

sudo nano /etc/fstab

Add the following line in the file. Replace nfs-server-ip with the IP address of the Ubuntu server.

nfs-server-ip:/home/username    /mnt/nfs-share      nfs       rw,soft,intr,noatime,x-gvfs-show

The above line will mount the home directory under /mnt/nfs-share directory in read and write mode. x-gvfs-show option will let you see the shared directory in your file manager.

Save and close the file. Then create the mount point.

sudo mkdir /mnt/nfs-share

Next, run the below command

sudo mount -a

Now you can access the server’s home directory in your file manager.

ubuntu nfs share

If you want to share your home directory with all computers in your home network, then add this line in /etc/exports file, supposing 192.168.1.1 is the IP address of your router.

/home/username     192.168.1.0/24(rw,sync,root_squash,subtree_check)

If you make any changes to /etc/exports file on the server side, then run the below command to tell NFS server to reload the /etc/exports file.

sudo exportfs -ra

If you can’t add/remove files or make any changes to the NFS share (Permission denied), it’s probably because you are acting as a different user. For example, If the file is owned by user1 on the server, then you should also act as user1 to make changes to the NFS share.

NFS over the Internet

By default, NFS is unencrypted. If you want to mount NFS over the Internet, you can encrypt the connection with VPN such as WireGuard.

I choose WireGuard because it’s the fastest VPN protocol.

A Simple Trick to Boost NFS Performance

You can enable the TCP BBR algorithm to boost server network performance.

Wrapping Up

That’s it! I hope this tutorial helped you set up NFS on Ubuntu. You might also want to read:

If you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 16 Average: 4]

8 Responses to “How to Set Up NFS Share on Ubuntu 22.04, 20.04

  • VaGNaroK Alkimist
    8 years ago

    Thanks for tutorial.

  • Sean Gross
    8 years ago

    I am a fan of Linux Babe, long may she reign

  • Mike DeLorenzo
    6 months ago

    I followed the instructions on both the server and client, but I get an error message on the client saying Unable to mount desktop-home mount: only root can mount….

    I then go to the command line to do sudo mount -a (guessing the above error is because root is not mounting the drive) and I get this error: mount.cfs: access denied by server while mounting 192.168.0.56:home/mike.

    Any ideas? Thanks!!

    • Mike …
      seems you’re missing a / before home (mount 192.168.0.56:/home/mike somewhere)

  • thank you very much from France, best website about linux for me

  • Shreyash
    4 years ago

    Hi,

    I am facing the following issue after running sudo mount -a command

    administrator@ubuntu:~$ sudo mount -a
    mount.nfs: access denied by server while mounting 10.155.224.133:/storage

    Any idea how to fix it?

    • Xiao Guoan (Admin)
      3 years ago

      Reload the /etc/exports file on the server.

      sudo exportfs -ra
  • Anderson
    3 years ago

    Can you make a tutorial on how to configure dovecot with maildir with nfs please?

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here