NFS
Setup guide for sharing files over a local network using NFS between Linux and Unix-like systems.
Server
Section titled “Server”-
Install
Section titled “Install”Install the NFS server package to enable file sharing.
Terminal window sudo apt update && sudo apt install nfs-kernel-server -y -
Add export
Section titled “Add export”Define the directory to share and specify client access in the NFS exports file.
Terminal window echo "{{NFS_SHARE_VAR}} {{CLIENT_IP_VAR}}(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports -
Apply export
Section titled “Apply export”Reload the NFS exports to apply the changes.
Terminal window sudo exportfs -ra -
Allow through firewall (optional)
Section titled “Allow through firewall (optional)”Open the NFS port to allow access from the specified client IP.
Terminal window sudo ufw allow from {{CLIENT_IP_VAR}} to any port nfs
Client
Section titled “Client”-
Install
Section titled “Install”Install the NFS client package to enable mounting remote shares.
Terminal window sudo apt update && sudo apt install nfs-common -y -
Create mount point
Section titled “Create mount point”Make a local directory where the shared files will be mounted.
Terminal window mkdir -p {{NFS_MOUNT_VAR}} -
Manual mount
Section titled “Manual mount”Mount the shared directory manually from the server to the local mount point.
Terminal window sudo mount {{SERVER_IP_VAR}}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}} -
Automount
Section titled “Automount”Add an entry to
/etc/fstabto mount the share automatically on boot.Terminal window sudo nano /etc/fstabTerminal window {SERVER_IP_VAR}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}} nfs noauto,x-systemd.automount,_netdev,nofail,timeo=5,retrans=2 0 0 -
Unmount
Section titled “Unmount”Unmount the shared directory. The
-l(lazy) flag defers unmounting until the directory is no longer in use.Terminal window sudo umount -l {{NFS_MOUNT_VAR}}