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)
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
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.
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 🙂
Thanks for tutorial.
I am a fan of Linux Babe, long may she reign
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
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?
Reload the
/etc/exports
file on the server.Can you make a tutorial on how to configure dovecot with maildir with nfs please?