Skip to content

nfs

Network File System — share directories between Linux hosts

--- Server Setup (Debian/Ubuntu) ---

To install the NFS server:

sudo apt install nfs-kernel-server

To start and enable the NFS server

sudo systemctl enable --now nfs-kernel-server

To check server status

sudo systemctl status nfs-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:

sudo exportfs -ra

To list currently exported shares

sudo exportfs -v

To reload NFS exports

sudo systemctl reload nfs-kernel-server

--- Client Setup (Debian/Ubuntu) ---

To install NFS client tools:

sudo apt install nfs-common

To mount an NFS share manually

sudo mount -t nfs <server-ip>:<remote-path> <local-mountpoint>

To mount with specific options

sudo mount -t nfs -o rw,soft,timeo=30 <server-ip>:<remote-path> <local-mountpoint>

To unmount an NFS share

sudo umount <local-mountpoint>

To list NFS shares exported by a server

showmount -e <server-ip>

--- Persistent Mounts (fstab) ---

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:

sudo mount -a

--- Diagnostics ---

To check NFS server RPC services:

rpcinfo -p <server-ip>

To view NFS statistics

nfsstat

To check mounted NFS filesystems

mount | grep nfs

To check open NFS connections

ss -tn | grep 2049

NFS uses port 2049 (TCP/UDP) — ensure firewall allows it

To allow NFS through ufw:

sudo ufw allow from <client-ip> to any port nfs

--- 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