Network File System — share directories between Linux hosts
--- Server Setup (Debian/Ubuntu) ---
To install the NFS server:
sudoaptinstallnfs-kernel-server
To start and enable the NFS server
sudosystemctlenable--nownfs-kernel-server
To check server status
sudosystemctlstatusnfs-kernel-server
Exports config file
/etc/exports
Example export entry:
/mnt/storage/cheat *(rw,sync,no_subtree_check,no_root_squash)
/mnt/data 192.168.1.0/24(rw,sync,no_subtree_check)
To apply changes to /etc/exports without restarting:
To add a persistent NFS mount in /etc/fstab:
: nfs rw,sync,hard,intr,timeo=30 0 0
Example for homelab cheat path:
192.168.1.10:/mnt/storage/cheat /mnt/storage/cheat nfs rw,sync,no_subtree_check 0 0
To mount all fstab entries without rebooting:
sudomount-a
--- Diagnostics ---
To check NFS server RPC services:
rpcinfo-p<server-ip>
To view NFS statistics
nfsstat
To check mounted NFS filesystems
mount|grepnfs
To check open NFS connections
ss-tn|grep2049
NFS uses port 2049 (TCP/UDP) — ensure firewall allows it
To allow NFS through ufw:
sudoufwallowfrom<client-ip>toanyportnfs
--- Common NFS Export Options ---
rw — allow read/write
ro — read-only
sync — write to disk before replying
no_subtree_check — improves reliability for exports of subdirs
no_root_squash — allow remote root to have root access (use carefully)
root_squash — map remote root to anonymous user (default, safer)
all_squash — map all users to anonymous