Install NFS Server on Raspberry Pi
Sep 28, 2023
Share files across devices on your local network!
Oct 24, 2023 03:53 PM
Network File System (NFS) is a distributed file system protocol that allows a user on a client computer to access files over a network like how local storage is accessed. I am using it to share files across devices on my local home network. Please do not use it as your only backup system. I strongly recommend you have a look at the 3-2-1 backup strategy here: https://www.seagate.com/blog/what-is-a-3-2-1-backup-strategy/
I am starting this installation with a freshly installed Raspberry Pi OS. To install and configure an NFS server on a Raspberry Pi, you will first need to update your package lists for upgrades, updates, and new package installations, and then install the necessary NFS server packages.
Here are the steps to do this:
sudo apt update sudo apt upgrade
sudo apt install nfs-kernel-server
Choose a directory that you want to share with your NFS clients. You can either use an existing directory or create a new one. For example, to create a new directory:
sudo mkdir -p /srv/nfs
You need to decide who can access the shared directory. You can either change ownership to a specific user or make it accessible to everyone. For instance, to make it accessible to everyone:
sudo chmod -R 777 /srv/nfs
You will need to edit the exports file to define which directories you want to share.
sudo nano /etc/exports
Add a line for the directory you want to share, for example:
Save the file and exit (
Ctrl + X,
This line exports the
/srv/nfs directory to all IP addresses (
*) with read/write permissions (
rw), ensures that changes made to files are written to disk (
sync), and disables subtree checking (
Once you have configured the exports file, restart the NFS server for the changes to take effect.
sudo systemctl restart nfs-kernel-server
If you are running a firewall on your Raspberry Pi, you will need to allow access to NFS. Here’s how to do it using
sudo ufw allow from [Client IP or Subnet] to any port nfs
[Client IP or Subnet] with the IP address or subnet of your NFS client.
Finally, to test if the NFS server is working properly, you can run the following command on a client machine:
showmount -e [Server IP Address]
[Server IP Address] with the IP address of your Raspberry Pi. If the setup is correct, this should list the directories exported by the NFS server.
On the client machine, you can mount the NFS share with the following command:
sudo mount -t nfs [Server IP Address]:/srv/nfs /path/to/mount/point
[Server IP Address] with the IP address of your Raspberry Pi and
/path/to/mount/point with the directory where you want to mount the NFS share on your client machine.
If you want the NFS share to be mounted automatically on the client every time it boots up, add an entry in the
/etc/fstab file on the client machine like this:
[Server IP Address]:/srv/nfs /path/to/mount/point nfs defaults 0 0
That’s it! You should now have a working NFS server on your Raspberry Pi.