NFS Setup
Preliminaries
Before we configure NFS, we need a couple preliminary pieces of information: the server private ip address and the client private ip address. The addresses should correspond to the same interface; in other words, if the NFS connection will be made over Wi-Fi, then we need the private ip address from the wireless interface of each machine (wlp1s0, wlan0, etc.). The connection could also be over the wired interface (enp1s0, eno1, etc.). In this case, we'll connect wirelessly.
To get these ip addresses, we'll run the following command on each machine.
ip r
---
# Results on server
default via 192.168.0.1 dev wlp6s0 proto static
10.0.0.0/24 dev enp3s0 proto kernel scope link src 10.0.0.10
192.168.0.0/24 dev wlp6s0 proto kernel scope link src 192.168.0.55
# Results on client
default via 192.168.0.1 dev wlan0 proto static metric 600
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.222 metric 600
Note that the server ip should be static. If dhcp is used, then the NFS connection will spontaneously break when the router hands out new ip addresses. We've got our ips, and we're all set.
# Server
wlp6s0 -> 192.168.0.55
# Client
wlan0 -> 192.168.0.222
Server Side
Install the nfs-kernel-server package. This depends on the nfs-common package, which should be installed by default. If it isn't, this command will install it.
sudo apt install nfs-kernel-server
Then, configure the /etc/exports file. Of course, add whatever directories you require. In my case, I need access to my jellyfin media and the files I store on my server. Note that the ip to which these directories will be exported is that of the client. Additional ip addresses can be added, separated by spaces.
sudo vi /etc/exports
---
# Add this to /etc/exports
/home/sean/ 192.168.0.222(rw,sync)
/home/jellyfin 192.168.0.222(rw,sync)
/media/behemoth/jellyfin 192.168.0.222(rw,sync)
To make the changes take effect, run this command. -a exports (or unexports) all directories, -r reexports all directories (important because it will modify the table when a directory is deleted, for example), and -v makes it all verbose so we know what's going on.
sudo exportfs -arv
Enable and start up the NFS Server daemon, and open port 2049 in the firewall (the port statically associated with NFSv4, which we are using).
sudo systemctl enable nfs-server.service
sudo systemctl start nfs-server.service
sudo ufw allow 2049/tcp
Client Side
Install NFS, create a mountpoint, and mount the remote filesystem. Note that we need the server ip address here.
sudo apt install nfs-common
sudo mkdir /mnt/sean-server
sudo mount 192.168.0.55:/ /mnt/sean-server
Next, we need to make the remote filesystem mount on system reboot. I pulled this one from the ArchWiki.[1]
sudo vi /etc/systemd/system/mnt-sean\\x2dserver.mount
---
# Add this to mnt-sean\\x2dserver.mount
[Unit]
Description=Mount sean-server on /mnt/sean-server
[Mount]
What=192.168.0.55:/
Where=/mnt/sean-server
Options=vers=4
Type=nfs
Timeoutsec=30
ForceUnmount=true
[Install]
WantedBy=multi-user.target
There's some funky stuff going on in the filename above, mnt-sean\\x2dserver.mount. systemd requires the .mount file to reflect the absolute path of the mountpoint but with hyphens instead of forward slashes.
For example, if you wish to mount a remote filesystem at /mnt/mountpoint, your .mount file would be named mnt-mountpoint.mount. Simple enough. Of course, I chose a cumbersome directory name, sean-server. systemd interprets the hyphen as a special character, in this case as a stand-in for the forward slash. To get systemd to recognize my directory name, I had to use systemd-escape.[2]
systemd-escape sean-server
# Returns sean\x2dserver
From there, it's necessary to escape the escape character so it is not removed, making the final filename.
sudo touch /etc/systemd/system/mnt-sean\\x2dserver.mount
# Creates mnt-sean\x2dserver.mount
Final Thoughts
There are countless adjustments that could be made to this configuration. The filesystem could be mounted over ethernet or automount could be set up so that the filesystem automatically connects when the mountpoint is accessed (a particularly useful feature when the client machine frequently moves on and off the local network). There are additional flags that can be added to the /etc/exports file beyond (rw,sync): it could be read-only ro, or subtree-check could be used. Additionally, the directories could be exported to an entire netgroup or subnet, i.e. /home/sean 192.168.0.0/24(ro,sync), so any device on it can mount the filesystem.





