Skip to content

Lesson 7 of 9 · 26m

NFS Operations: Exports, Identity Mapping, and Failure Behavior

Configure NFS with explicit export semantics, UID/GID reality, mount options, firewall boundaries, and an understanding of stale mounts and locking.

NFS looks simple because mounting a directory is simple. Operating it well means understanding identity, network failure, server reboots, locking, and the fact that Unix permissions do not become centralized identity management just because a share is network-accessible. Most NFS incidents are not exotic. They are mismatched UIDs, overly broad exports, blocked ports, or clients hanging because the server disappeared.

Exports are policy, not convenience

A minimal /etc/exports entry might be:

/srv/shared 10.20.30.0/24(rw,sync,no_subtree_check,root_squash)

Apply and inspect it:

exportfs -ra
exportfs -v

Important options:

rw / ro              write access at export layer
sync / async         commit semantics before server reply
root_squash          remote root becomes nobody/nogroup
no_root_squash       remote root remains root; usually dangerous
all_squash           all users mapped to anonymous identity
no_subtree_check     predictable behavior for exported directory boundaries
fsid                 stable filesystem identity, important for failover

Never export more broadly than required. *(rw) on an untrusted network is not storage administration; it is incident generation.

Identity is numeric

Traditional NFSv3 carries numeric UID/GID values. A user named alex on the client and alex on the server are not automatically the same principal. If client UID 1001 owns files and server UID 1001 is a different person, permissions still follow the number. Centralize identity with LDAP, Kerberos, directory services, or disciplined UID/GID allocation. NFSv4 improves idmapping through idmapd, but the underlying lesson remains: names are presentation, numbers are enforcement.

Client mounts control failure behavior

mount -t nfs -o vers=4.2,hard,intr,noatime   fileserver:/srv/shared /mnt/shared

hard retries indefinitely and preserves write semantics better, but applications can hang when the server disappears. soft returns errors but can silently corrupt application assumptions because writes may fail after the application believes progress occurred. In practice, hard mounts with good monitoring and clean service dependencies are often safer for critical data. For disposable read-only data, softer behavior may be acceptable.

Firewalling and NFSv4 simplification

NFSv3 historically involved several dynamically assigned services: rpcbind, mountd, statd, lockd. Firewalls made this miserable. NFSv4 normally concentrates traffic on TCP 2049; allow the firewall service with firewall-cmd --permanent --add-service=nfs && firewall-cmd --reload, then verify with ss -lntup | grep 2049. Do not infer security from port filtering alone. Export rules, squash behavior, Kerberos integrity, and network trust still decide who can read or modify files.

Locking and application suitability

NFS is not a universal replacement for local disk. Databases often have strict fsync, locking, and latency requirements. Some work well only with carefully validated NFS versions and mount options. Others corrupt under poorly configured caching or failover. Read vendor requirements, test failover, and remember that flock behavior across NFS has historically differed by version and implementation.

Field notes

  • showmount -e server is reconnaissance for you and attackers; restrict who can query it.
  • Stale file handles often mean the export path or underlying filesystem identity changed.
  • no_root_squash is occasionally necessary for trusted automation, but treat it as root-equivalent network access.
  • Mount units in systemd should declare dependencies so applications do not write into an empty mountpoint directory.
  • Test server reboot behavior before production. A mount that recovers cleanly in a diagram may hang every worker in reality.

Was this lesson helpful?

Sign in to rate