NFS v4-only on modern Debian
A small how-to on configuring a modern Debian 12 "bookworm" installation using systemd as its init system for serving NFS v4 shares, disabling the services related to legacy NFS v2 and NFS v3.
Until the Debian maintainers realize that v4 came out at the turn of the millenia (23 years ago and counting), and that v3 is just an archaic nuissance that is virtually unused at this point, we'll have to go through this procedure.
All commands must be run as root.
For clients
-
Install the NFS common package, which includes the needed
mount.nfscommand. This pulls the rpcbind package that is only used for v2 and v3, but can't do shit about it:Text Onlyapt-get install nfs-common -
Disable completely rpcbind service and socket:
Text Onlysystemctl mask rpcbind rpcbind.socket systemctl stop rpcbind rpcbind.socket -
Disable completely the rpc-statd-notify service:
Text Onlysystemctl mask rpc-statd-notify systemctl stop rpc-statd-notify
Done.
For servers
-
Install the NFS server. Since it depends on common, it will also pull the useless rpcbind package.
Text Onlyapt-get install nfs-kernel-server -
Disable completely rpcbind service and socket:
Text Onlysystemctl mask rpcbind rpcbind.socket systemctl stop rpcbind rpcbind.socket -
Disable completely rpc-statd and rpc-statd-notify services:
Text Onlysystemctl mask rpc-statd rpc-statd-notify systemctl stop rpc-statd rpc-statd-notify -
Override the nfs-kernel-server unit to disable v3:
Text Onlymkdir -p /etc/systemd/system/nfs-server.service.d cat <<'EOF' >/etc/systemd/system/nfs-server.service.d/override.conf [Service] ExecStart= ExecStart=/usr/sbin/rpc.nfsd --no-nfs-version 3 EOFThis can also be achieved using
systemctl edit nfs-serverand manually entering:Text Only[Service] ExecStart= ExecStart=/usr/sbin/rpc.nfsd --no-nfs-version 3 EOFWe don't need to disable v2 since the kernel (as of Debian 12 "bookworm") does not support it, and in fact the servicec fail to start if we explicitely attempt to disable it.
The reason we have an empty
ExecStart=before the actual command, is thatExecStartis a list, and that's the means to clear it to remove the original start command before we push the correct one. -
Override the nfs-mound unit to disable both v2 and v3:
Text Onlymkdir -p /etc/systemd/system/nfs-mountd.service.d cat <<'EOF' >/etc/systemd/system/nfs-mountd.service.d/override.conf [Service] ExecStart= ExecStart=/usr/sbin/rpc.mountd --no-nfs-version 2 --no-nfs-version 3 EOFThis can also be achieved using
systemctl edit nfs-mountdand manually entering:Text Only[Service] ExecStart= ExecStart=/usr/sbin/rpc.mountd --no-nfs-version 2 --no-nfs-version 3 EOFUnlike the server,
rpc.mountdstill supports v2, so we also have to pass that. -
Restart both services:
Text Onlysystemctl restart nfs-server nfs-mountd -
Check using
ss -lutpnthat the port 2049 remains open (only port required for NFS v4), and thatrpc.mountdis not listening in any port.