Where to start First steps track · 15 stages
Linux Labs

NFS network filesystem

4 min Ubuntu 24.04 · NFSv4

Network directories over NFS — exporting on the server, mounting on the client, permissions.

Cheat sheet

5 commands Printable version
  • server:
  • /etc/exports → /srv/share 10.0.0.0/24(rw,sync,no_subtree_check)
  • sudo exportfs -ra
  • sudo exportfs -v
  • client:
  • showmount -e server
  • sudo mount -t nfs -o vers=4.2 server:/srv/share /mnt
  • fstab: server:/path /mnt nfs defaults,_netdev,nofail 0 0
  • nc -zv server 2049 is the NFS port reachable

Overview

NFS gives access to a server's directories over the network as if they were local. The server exports a directory, the client mounts it (mount). Common between Linux machines.

  • server: the nfs-kernel-server package, exports in /etc/exports;
  • client: the nfs-common package, mounting via mount -t nfs.

Recipes

2

Server

bash
sudo apt install nfs-kernel-server
sudo mkdir -p /srv/share

/etc/exports (one line per export): path network(options):

/srv/share   10.0.0.0/24(rw,sync,no_subtree_check)
/srv/ro      10.0.0.0/24(ro,sync,no_subtree_check)
/srv/admin   10.0.0.5(rw,sync,no_root_squash)   # trust the client's root (careful!)
bash
sudo exportfs -ra                 # reread /etc/exports (-r), no restart needed
sudo exportfs -v                  # show active exports with their options
sudo systemctl status nfs-server

Options: rw/ro, sync (safe) / async (fast), root_squash (the client's root maps to nobody, the default), no_subtree_check (recommended).

Client

bash
sudo apt install nfs-common
showmount -e 10.0.0.1             # what the server exports
sudo mount -t nfs 10.0.0.1:/srv/share /mnt/share
sudo mount -t nfs -o vers=4.2 10.0.0.1:/srv/share /mnt/share   # an explicit version
sudo mount -t nfs -o ro,soft,timeo=50 10.0.0.1:/srv/ro /mnt/ro

# permanently — in /etc/fstab:
#   10.0.0.1:/srv/share  /mnt/share  nfs  defaults,_netdev,nofail  0  0
nfsstat -m                        # parameters of the mounted NFS shares

Troubleshooting

5

mount.nfs: access denied by server

The client's IP doesn't match the mask in /etc/exports, or exportfs -ra wasn't run after editing it. Check showmount -e server and the export line itself.

Ownership/permissions on the mount look "wrong"

NFS maps by UID/GID — the client and server need matching ones (or set up idmapping for NFSv4). The client's root is "squashed" to nobody by default (root_squash).

Connection timed out / mount hangs

The firewall or the service. NFSv4 uses port 2049/tcp. Check ss -tlnp on the server, and whether the port is reachable: nc -zv server 2049.

Processes hang when the server is unreachable (D state)

A "hard" mount (the default) hangs processes indefinitely. For non-critical data, use soft,timeo=50,retrans=2; in fstab, add _netdev,nofail.

Stale file handle

The export was recreated, or the filesystem was remounted on the server. Remount on the client (umount/mount), with -o remount if needed.

See also

  • mount — Mounting filesystems, persistent mounts via /etc/fstab, UUIDs.
  • firewall — Traffic filtering — simple ufw and low-level nftables.
  • permissions — The Unix permission model — read/write/execute, owner/group/other, special bits.
Loading…