linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Protocols/nfs

kb/protocols ── Protocols ── intermediate

NFS: Network File System

NFS is a network file system from Sun. v3 is stateless, v4.1+ is stateful with delegations and pNFS. /etc/exports on the server, mount -t nfs on the client. root_squash, sync/async, and the lock manager are the main options.

view as markdownaka: nfsv3, nfsv4, nfs-server, nfs-client, exports

Why NFS

Network File System is the standard way to "mount someone else's disk over the network" on Unix. It is transparent: open/read/write/close work like on a local FS, and everything is cached by the page cache. It is used for:

  • Shared home directories in corporate networks
  • Storage for VM images (KVM, Proxmox)
  • ML datasets shared between GPU nodes
  • Backup targets
  • Kubernetes Persistent Volumes (NFS-CSI driver)

Alternatives: SMB/CIFS (native to Windows), [[cmd-rsync|rsync]] (for periodic sync, not a live mount), CephFS/GlusterFS (distributed), object storage (S3, for non-POSIX).

NFSv3 vs NFSv4

Traitv3 (1995)v4.0 (2003) / v4.1 (2010)
Statestatelessstateful
TransportUDP or TCPTCP only
Ports111 (rpcbind) + dynamic2049 single port
Lock managerrpc.lockd (separate)built in
Authsys (uid/gid from RPC)+ Kerberos (krb5/krb5i/krb5p)
Delegationsnoyes (read/write delegation)
pNFSnoyes in v4.1 (parallel NFS)
ACLPOSIX via protocol-extensionNFSv4 ACL (Windows-style)
Through NAT/firewallhard (dynamic ports)simple (one port)

NFSv3 is still alive in legacy and embedded. For new code use NFSv4.1+.

Server: /etc/exports

bash
# Install
apt install nfs-kernel-server     # Debian/Ubuntu
dnf install nfs-utils              # RHEL
# Create a share
mkdir -p /srv/nfs/data
chown nobody:nogroup /srv/nfs/data

/etc/exports:

/srv/nfs/data    10.0.0.0/24(rw,sync,no_subtree_check,root_squash)
/srv/nfs/backup  10.0.0.5(ro,sync,no_subtree_check)  10.0.0.6(rw,sync,no_subtree_check)
/srv/nfs/krb5    *(rw,sync,sec=krb5p,no_subtree_check)

Apply:

bash
exportfs -ra                # re-export everything
exportfs -v                 # show active exports
systemctl enable --now nfs-server

Main exports options

OptionWhat
rw / roaccess for the subnet
sync (default)reply to the client only after fsync
asyncreply right away, fsync later, faster, but data is lost if the server crashes
root_squash (default)the client's root maps to nobody, a protection
no_root_squashthe client's root stays root, very dangerous
all_squashall users map to nobody (for a public share)
anonuid=, anongid=what to map squashed users to
subtree_check / no_subtree_checkcheck that the path is inside the export; no_subtree_check is faster, default on modern systems
`sec=syskrb5
nohidefor nested mounts on the server
crossmntcross mount points while walking

Client: mount

bash
apt install nfs-common              # Debian
mount -t nfs server:/srv/nfs/data /mnt/data
mount -t nfs4 server:/srv/nfs/data /mnt/data

In [[mount-and-fstab|fstab]]:

fstab
server:/srv/nfs/data  /mnt/data  nfs4  rw,_netdev,vers=4.2,hard,timeo=600,retrans=3,nofail  0 0

Main mount options:

OptionWhat
vers=4.2force the version (default is auto-negotiate)
hard (default)on a lost connection, block I/O until it comes back
softreturn an I/O error after timeo*retrans ms, dangerous, may corrupt data
timeo=Ntimeout in deciseconds (600 = 60 sec)
retrans=Nhow many retries before declaring the "server dead"
_netdevbring up the network first (for systemd)
nolockwithout NLM (for read-only mounts)
nfsvers=3,proto=tcp,port=2049for hard pinning of v3
noatimeas everywhere, turn off atime
nconnect=N(5.3+) N TCP connections to the server, boosts throughput

hard vs soft: always use hard. soft gives failover in theory, but in practice it corrupts files on short network outages.

Caching and consistency

NFS does not guarantee strict "wrote on one node, visible on another immediately". The model is close-to-open consistency: on close() the client flushes, and on open() another client checks mtime via GETATTR and invalidates its cache.

This means NFS is not suitable for a shared DB (different clients will not see edits). For a shared home, build output, or ML dataset, it is fine.

Kerberos: sec=krb5p

Without Kerberos the NFS client states its own UID through RPC AUTH_SYS, with trust at the level of "we use the same UIDs on every machine". In multi-user enterprise environments that is weak.

With sec=krb5p, every operation is authenticated by the user's Kerberos ticket, and the payload is encrypted. It requires:

  • A KDC (kerberos)
  • The service principal nfs/server.example.com@REALM in the server keytab
  • idmapd.conf to map user@REALM to a UID on the clients

It is complex, but the only production-grade option for shared homes.

NFSv3 vs NFSv4 firewall

v3:

  • 111 (portmap/rpcbind) TCP/UDP
  • 2049 (nfs) TCP/UDP
  • mountd, statd, lockd, rquotad on dynamic ports!
  • Fix: pin the ports in /etc/nfs.conf

v4:

  • 2049 TCP only, everything through one port, including the lock manager
  • Works through NAT without pain

This is one of the main reasons to migrate to v4.

When something goes wrong

  • mount.nfs: Connection refused: nfs-server is not running or is not listening on 2049 (ss -tlnp | grep 2049).
  • ls /mnt/data hangs forever: a hard mount with the server unreachable. umount -f -l /mnt/data (lazy umount).
  • Stale file handle: the file was deleted on the server while the client holds an fd. umount && mount fixes it. Less frequent on v4.1+.
  • Other users' files show as nobody:nogroup: no idmapd mapping. On NFSv4, make sure nfs-idmapd is running and that Domain = matches in /etc/idmapd.conf on both ends.
  • Performance is slow on large files: wsize=1048576,rsize=1048576, nconnect=4 (5.3+), and check jumbo frames on the wire.
  • Permission denied despite mode 777: root_squash maps root to nobody. Create files as a regular user, or use no_root_squash (only on a trusted network!).
  • Lockd does not work between hosts: on v3 you need rpc.statd plus portmap; on v4 it is built in. Check that the firewall is not blocking the statd port on v3.

Alternatives

  • SMB/CIFS (Samba): the Windows standard, also works on Linux
  • CephFS: distributed, replicated, for scale
  • GlusterFS: same idea, deprecated after IBM absorbed Red Hat
  • sshfs (FUSE): a tunnel over SSH, for one-off cases
  • S3/MinIO: for non-POSIX object storage

§ команды

bash
exportfs -v

All active NFS exports, what is actually being served

bash
exportfs -ra

Reread /etc/exports without restarting nfs-server

bash
showmount -e nfs.example.com

From the client side: which shares the remote server serves (v3 only)

bash
mount -t nfs4 -o vers=4.2,hard,nconnect=4 server:/data /mnt/data

Mount with v4.2 plus 4 parallel TCP connections, boosts throughput

bash
nfsstat -c

Client RPC operation stats, how many read/write/getattr

bash
rpcinfo -p server

Which NFS services and ports the remote server listens on, debug a v3 firewall

bash
cat /proc/fs/nfsd/clients/*/info 2>/dev/null

Which clients hold a connection to the NFSv4 server right now

§ см. также

  • mount-and-fstabmount and /etc/fstab: attaching filesystems`mount` attaches a block device or filesystem to a mount point in the tree. `/etc/fstab` is the list of what to mount at boot.
  • cmd-rsyncrsync: incremental file synchronizationrsync copies only the changed blocks of files, locally or over SSH. `-avz` is the baseline combination (archive + verbose + compress). `--delete` mirrors. `--dry-run` is required before the first run.
  • tcp-handshakeTCP three-way handshakeTCP connection opens with three packets: SYN from the client, SYN-ACK from the server, ACK from the client. After that the connection is Established and data transfer can begin.
  • udp-basicsUDP: User Datagram ProtocolUDP delivers datagrams without establishing a connection, without retransmits, and without ordering guarantees. Header is 8 bytes. Use it for DNS, DHCP, QUIC, VoIP, and any case where latency matters more than reliability.
  • file-permissionsFile permissions: rwx and chmodEvery file has three permission sets: for the owner, the group, and others. Each set is three bits: read (r), write (w), execute (x). You change them with `chmod`.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies