NFS (Network File System) lets clients mount remote directories over the network so they behave like local file systems. Debian 12 (Bookworm) ships a modern NFS stack: NFSv2 is disabled, while NFSv3 and NFSv4 (including 4.1 / 4.2) are supported. NFSv4.2 adds ACLs, server-side copy, sparse files, reservations, and other features on top of v4.
This guide walks through a typical lab or small-network setup: Debian 12 NFS server, Debian/Ubuntu-style client, /etc/exports tuning, UFW, manual mounts, and fstab persistence. Replace example addresses (10.70.5.221, 10.70.5.170, 10.70.5.0/24) with your server IP, client IP, and trusted subnet.
Related posts
- How to Set Up NFS Server and Client on Ubuntu 20.04
- How to Set Up NFS Server and Client on Rocky / Alma Linux 8
- How to Install and Configure Samba File Sharing on Ubuntu 20.04
Prerequisites
- Two Debian 12 hosts (or one server and a mixed Linux client), fully patched, with sudo
- Reliable L3 connectivity between client and server (latency and MTU matter on WAN)
- Agreement on NFS version: this article assumes NFSv4.x for mounts (
vers=4.2in typicalmountoutput)
1. Update the system
On server and client:
| |
2. Install the NFS server (Debian 12)
| |
nfs-kernel-server pulls in kernel NFS service support and userspace helpers.
Enable protocol versions
Check what the kernel NFS server advertises:
| |
Typical Debian 12 output:
| |
-2 means NFSv2 off; +4.2 means NFSv4.2 is available.
Ensure /etc/exports exists
If systemctl status nfs-server logs “can’t open /etc/exports for reading”, create an empty file once (the package normally ships a template):
| |
Then define real exports (next section) and run exportfs -arv.
Start and enable NFS
| |
Supporting pieces (rpcbind, rpc.mountd, nfsd, lock/stat helpers, idmapd where used) are managed via dependencies; you rarely start them by hand on a current Debian NFS server.
Tuning (thread count, host exports, etc.) can go in /etc/default/nfs-kernel-server and /etc/nfs.conf when you outgrow defaults.
3. Firewall (UFW)
If UFW is active on the server, allow NFS-related traffic from trusted clients only whenever possible.
NFSv4 primarily needs TCP 2049:
| |
The ufw allow nfs shortcut is convenient but broad; prefer allow from … to any port nfs (or 2049/tcp) so only your subnet reaches the export.
NFSv3 also uses RPC services (rpcbind, mountd, status, etc.), often on dynamic or multiple ports—if you must support v3 through a firewall, you will usually pin RPC ports in /etc/nfs.conf and open those explicitly, or standardize on v4-only behind UFW.
4. Create export directories and permissions
Create mount points for two example shares (general files and backups):
| |
Who owns the files?
- With
root_squash(default), root on the client is mapped to an unprivileged user on the server—oftennobody. Many tutorials setchown nobody:nogroupso world-like access works for simple labs. - With
no_all_squash, non-root UIDs from the client map to the same numeric UID on the server, which is useful when UIDs match (LDAP, matching local accounts, dedicated backup user). Misaligned UIDs cause “permission denied” or wrong ownership. - For production, prefer consistent identity (SSSD/LDAP) or explicit
anonuid/anongidwithall_squashfor heavily locked-down shares.
Example for a simple open lab share:
| |
Tighten chmod for anything beyond a test network.
5. Configure /etc/exports
Syntax:
| |
Edit:
| |
Example (adjust IPs and subnets):
| |
| Option | Meaning |
|---|---|
| rw / ro | Read-write or read-only |
| sync | Commit server writes before replying (safer, slower than async) |
| no_subtree_check | Avoids subtle issues when files under an export are renamed (common recommendation) |
| root_squash | Map client root to unprivileged user (default, keep unless you know you need no_root_squash) |
| all_squash | Map all users to anonymous UID/GID (often paired with anonuid / anongid) |
| no_all_squash | Do not squash non-root UIDs; they must exist on the server (numeric match) |
Apply exports:
| |
-a export all, -r re-read /etc/exports, -v verbose.
6. Debian / Ubuntu client: packages and discovery
On the client:
| |
RHEL-family equivalent (if your client is Rocky/Alma/Fedora):
| |
List exports the server offers:
| |
Example:
| |
If this fails, fix routing, firewall, or exports ACLs before mounting.
7. Mount shares
Create mount points:
| |
Mount (NFSv4 is selected automatically on current kernels when the server supports it):
| |
Verify:
| |
8. Persist mounts in /etc/fstab
Use absolute paths and _netdev so systemd waits for the network before mounting:
| |
Edit safely:
| |
Test fstab without rebooting:
| |
Optional mount options: noatime, nfsvers=4.2, timeo=600, soft vs hard (understand data integrity trade-offs before using soft).
9. Functional test
On the server:
| |
On the client:
| |
On the client, create a file:
| |
On the server:
| |
10. Unmount
Use the client’s mountpoint paths (not the server’s export paths):
| |
You cannot unmount a busy mount: leave the directory (cd ~) and stop processes using the files.
If fstab still references the mount, comment those lines out or use umount after mount -a tests.
Troubleshooting
| Symptom | Checks |
|---|---|
showmount: RPC: Unable to receive | Server down, firewall, wrong IP, or RPC blocked (especially for v3) |
Permission denied on create/write | Export rw, directory ownership/modes, root_squash / UID mapping |
| Wrong user shown as owner | NFSv4 idmap / numeric UID mismatch; align identities or use all_squash with fixed anon IDs |
| Stale file handle | Server export path renamed; remount client |
| Export not visible | exportfs -s, typos in /etc/exports, client IP not in allow list |
Server logs:
| |
Security reminders
- Export only to known hosts or subnets; never use
*on untrusted networks. - Avoid
no_root_squashunless you fully trust the client root. - Prefer NFSv4 + Kerberos (
sec=krb5p) in sensitive environments;sec=sys(this article) sends UIDs/GIDs without strong authentication between nodes. - Combine NFS with VLANs, VPN, or private RFC1918 addressing so shares are not exposed on the public Internet.
Conclusion
On Debian 12, nfs-kernel-server and a clear /etc/exports give you NFSv4.2-capable exports; nfs-common on clients, _netdev in fstab, and tight firewall rules complete a maintainable small-network deployment. Match this guide’s placeholders to your IPs, verify ownership against your identity strategy, then harden exports and mount options before production workloads.