You have a small fleet of application servers that need to share files — uploads, build artifacts, a CMS media directory — and the application doesn’t speak object storage. NFSv4 on Ubuntu 24.04 gives you a kernel-mode, well-understood shared filesystem in about ten minutes, with a single TCP port (2049), proper identity mapping, and far less wire-protocol baggage than the v3 protocol many tutorials still ship. This article walks the install and the v4-only configuration we use as the default when we provision shared storage for clients who aren’t ready to refactor for S3.
How to verify
Confirm the kernel supports NFSv4 and the userspace tools are recent enough:
uname -r
modinfo nfsd | head -5
apt list --installed nfs-kernel-server nfs-common 2>/dev/null
# After install:
systemctl status nfs-server nfs-idmapd
ss -tlnp | grep ':2049'
rpcinfo -p localhost | head -20
exportfs -v
On the client, you want to see the negotiated protocol is 4.2 (or at least 4.1):
mount -t nfs4 -o vers=4.2 nfs.example.internal:/ /mnt/shared
findmnt -t nfs4
nfsstat -m
What’s happening
NFSv4 collapsed everything the v2/v3 protocol family did across half a dozen RPC services (mountd, statd, lockd, portmapper) into a single stateful protocol on TCP/2049. That’s why an NFSv4-only server doesn’t need rpcbind, doesn’t need NLM locks, and doesn’t need a host of conntrack-unfriendly UDP ports. The export is presented as a single pseudo-root filesystem — clients mount server:/, not server:/srv/nfs, and they see whatever directories you’ve exported as branches of that root. Underneath, those branches can live on different filesystems or different paths; the pseudo-root hides that.
Identity mapping is the other v4-specific concern. The protocol carries user identities as strings (alice@example.com), and the idmapd daemon on each side resolves those to local UIDs. When idmapd is misconfigured or the domain string doesn’t match between server and client, every file appears owned by nobody:nogroup even though the numeric UIDs match. Set Domain = example.internal (or whatever realm name you’ve picked) identically on every node, and set sec=sys on the export if you’re not running Kerberos — that’s the path of least resistance for an internal trust boundary.
There’s also a question of what you protect. sec=sys trusts the client’s claim about UIDs; anyone with root on a client can be any user on the export. That’s fine inside a VPC perimeter where you control the client OS. If you don’t, you need Kerberos (sec=krb5p), and the operational story changes considerably — keytabs, principals, time sync. We deploy sec=sys over a private network with a security group locking 2049 to the client subnet, and we audit any deviation.
The procedure
-
Install the server package and disable v3 entirely:
sudo apt update sudo apt install -y nfs-kernel-server sudo systemctl enable --now nfs-server -
Pin to v4 by editing
/etc/nfs.conf:[nfsd] vers2=n vers3=n vers4=y vers4.0=n vers4.1=y vers4.2=y tcp=y udp=n threads=16 -
Set the idmap domain in
/etc/idmapd.conf:[General] Verbosity = 0 Domain = example.internal [Mapping] Nobody-User = nobody Nobody-Group = nogroup -
Create the export root and a subdirectory, both owned by a service UID that exists on every client:
sudo mkdir -p /srv/nfs/uploads sudo chown -R 2000:2000 /srv/nfs sudo chmod 2770 /srv/nfs/uploads -
Define
/etc/exports:/srv/nfs 10.0.0.0/16(rw,sync,fsid=0,no_subtree_check,crossmnt) /srv/nfs/uploads 10.0.0.0/16(rw,sync,no_subtree_check,sec=sys)The
fsid=0flag marks/srv/nfsas the NFSv4 pseudo-root. -
Apply and restart:
sudo exportfs -ra sudo systemctl restart nfs-server nfs-idmapd sudo exportfs -v -
On a client (with the same
Domainin its/etc/idmapd.conf):sudo apt install -y nfs-common sudo mkdir -p /mnt/uploads sudo mount -t nfs4 -o vers=4.2,_netdev,hard,intr,timeo=600 nfs.example.internal:/uploads /mnt/uploads echo "nfs.example.internal:/uploads /mnt/uploads nfs4 vers=4.2,_netdev,hard,intr,timeo=600 0 0" | sudo tee -a /etc/fstab
Operational notes
- The
hardmount option is correct for almost every server-to-server workload.softwill return EIO during a network blip and corrupt write-after-read patterns the application thinks succeeded. - If files appear as
nobody:nogroupon the client, runnfsidmap -cto flush the keyring and check that/etc/idmapd.confhas identicalDomainvalues on both sides. no_subtree_checkis the modern default — leave it on. The legacysubtree_checkbreaks on file renames across subdirectories.- Without a dedicated VLAN, lock the firewall:
ufw allow from 10.0.0.0/16 to any port 2049 proto tcpand nothing else. - Quota enforcement on NFSv4 needs
quotapackage on the server andusrquota,grpquotaon the underlying filesystem mount — not enabled by thenfs-kernel-serverinstall.
In the engagements we run, shared NFSv4 is rarely the destination state — most clients are migrating off it toward object storage or a clustered filesystem — but it’s a clean stopgap when the application predates the shift. We standardize the v4-only configuration above, monitor for nobody:nogroup regressions after every client image rebuild, and put the export behind a highly available pair when downtime tolerance demands it.