NFS: Network
File Systems

Mount and unmount network file systems using NFS

CIS126RH | RHEL System Administration 1
Mesa Community College

NFS (Network File System) allows Linux systems to share directories over the network and mount them as if they were local filesystems. Shared home directories, centralised application data, and read-only software repositories are all common NFS use cases in enterprise environments. This module covers discovering available NFS exports, mounting them temporarily and persistently, and unmounting them cleanly. The client-side NFS skills are tested on the RHCSA exam.

Learning Objectives

  1. Explain how NFS works — Describe the NFS client-server model, NFS versions, and what the client needs to mount a remote share
  2. Discover and mount NFS shares — Use showmount to list available exports and mount with NFS-specific options to attach a remote share
  3. Configure persistent NFS mounts in /etc/fstab — Write correct fstab entries for NFS filesystems including the _netdev option and verify them
  4. Use autofs for on-demand mounting — Install and configure the autofs service to mount NFS shares automatically when they are accessed

How NFS Works

NFS is a client-server protocol. The server exports directories; the client mounts them and accesses the files as if they were local.

  • The NFS server runs nfs-server.service and lists exported directories in /etc/exports
  • The NFS client mounts the server's exports using the mount command or /etc/fstab
  • File access goes over the network — reads and writes are sent to the server
  • RHEL 9 supports NFSv4 (default) and NFSv3
  • NFSv4 uses TCP port 2049 only; NFSv3 requires multiple RPC ports
  • The client needs the nfs-utils package for NFS tools
NFSv4 is the RHEL 9 default

NFSv4 is simpler to firewall (single port 2049/TCP), supports Kerberos authentication, and provides better performance than NFSv3. The mount command negotiates NFSv4 by default. Explicitly specify nfsvers=3 only when the server does not support NFSv4.

Installing NFS Client Tools

The NFS client tools are in the nfs-utils package. This package provides mount.nfs, showmount, and the kernel NFS client support files.

# Install nfs-utils if not already present
$ sudo dnf install -y nfs-utils

# Verify key NFS client tools are available
$ which showmount
/usr/sbin/showmount

$ rpm -q nfs-utils
nfs-utils-2.5.4-26.el9.x86_64

# Check which NFS versions are supported by the kernel
$ cat /proc/fs/nfsfs/volumes

# The rpcbind service is needed for NFSv3 only
$ sudo systemctl enable --now rpcbind   # only if using NFSv3
nfs-utils is usually already installed on RHEL 9

Most RHEL 9 installations include nfs-utils as part of the default package set. Check with rpm -q nfs-utils before attempting to install. The dnf install is idempotent — safe to run even if already installed.

Discovering NFS Exports: showmount

showmount queries an NFS server and lists the directories it is currently exporting — the prerequisite to mounting.

# List all exports from an NFS server
$ showmount -e servera
Export list for servera:
/exports/data    *
/exports/shared  192.168.1.0/24
/home            *(ro,sync)

# List exports using the server's IP address
$ showmount -e 192.168.1.10

# List which clients have each export mounted
$ showmount -a servera
All mount points on servera:
192.168.1.20:/exports/data
192.168.1.21:/exports/shared

# List only the exported directories (no client info)
$ showmount -d servera
showmount -e SERVER is the starting point

On the exam, the task will specify the NFS server hostname or IP address. Run showmount -e SERVERNAME first to confirm the export path before constructing the mount command.

Mounting an NFS Share

The NFS mount syntax is SERVER:/export/path — server hostname or IP, colon, and the exported directory path.

# Basic NFS mount — filesystem type and options auto-detected
$ sudo mkdir -p /mnt/nfsdata
$ sudo mount -t nfs servera:/exports/data /mnt/nfsdata

# Mount with explicit NFSv4
$ sudo mount -t nfs4 servera:/exports/data /mnt/nfsdata

# Mount with NFSv3
$ sudo mount -t nfs -o nfsvers=3 servera:/exports/data /mnt/nfsdata

# Mount read-only
$ sudo mount -t nfs -o ro servera:/exports/data /mnt/nfsdata

# Verify the mount succeeded
$ mount | grep nfs
servera:/exports/data on /mnt/nfsdata type nfs4 (rw,relatime,...)

$ df -hT /mnt/nfsdata
Filesystem             Type  Size  Used Avail Use% Mounted on
servera:/exports/data  nfs4   10G  3.2G  6.8G  32% /mnt/nfsdata

NFS Mount Options

NFS-specific mount options control performance, reliability, and behaviour when the server is unreachable.

Option Meaning Default
rw / roRead-write or read-only mountrw
sync / asyncWrite data to server synchronously or allow bufferingasync
hard / softHard: retry forever if server unreachable. Soft: return error after timeouthard
intrAllow Ctrl+C to interrupt hung NFS operationsoff
timeo=NTimeout in tenths of a second before retrying600
retrans=NNumber of retransmissions before giving up (soft) or logging (hard)2
nfsvers=4Force NFS version 4 (or 3)4 on RHEL 9
_netdevTell systemd to mount only after network is availableoff — required in fstab
Always use hard mounts in production

A soft mount returns an I/O error to applications when the server is temporarily unreachable, potentially causing data corruption. hard (the default) retries until the server responds — applications pause but data is safe.

Persistent NFS Mounts in /etc/fstab

For an NFS mount to survive reboots, add it to /etc/fstab with the _netdev option — which tells systemd to wait for the network before mounting.

# /etc/fstab entry for an NFS share
# SERVER:/path  MOUNTPOINT  nfs  OPTIONS  0 0

servera:/exports/data    /mnt/nfsdata  nfs  defaults,_netdev  0 0

# With explicit NFS options
servera:/exports/data    /mnt/nfsdata  nfs  rw,sync,hard,_netdev  0 0

# Read-only NFS share (e.g. software repository)
servera:/exports/software  /software   nfs  ro,_netdev             0 0

# Test the fstab entry
$ sudo mount -a
$ df -hT /mnt/nfsdata
$ findmnt --verify
NFS fstab rules

NFS fstab entries always have _netdev in the options field, 0 for the dump field, and 0 for the fsck order — NFS filesystems are never checked by fsck.

Unmounting NFS Shares

NFS shares are unmounted with umount just like local filesystems, but there are additional considerations when the server is unavailable.

# Unmount by mount point
$ sudo umount /mnt/nfsdata

# Unmount when the NFS server is unreachable (lazy unmount)
$ sudo umount -l /mnt/nfsdata

# Force unmount even with open files (use with caution)
$ sudo umount -f /mnt/nfsdata

# Lazy + force for an unreachable server with processes using the mount
$ sudo umount -l -f /mnt/nfsdata

# If normal umount hangs — check for processes using the mount
$ sudo fuser -vm /mnt/nfsdata
$ sudo lsof /mnt/nfsdata

# Confirm unmount succeeded
$ mount | grep nfsdata
# No output = successfully unmounted
NFS umount can hang if server is unreachable

If the NFS server becomes unreachable while a hard mount is active, even umount will hang waiting for the server. Use umount -l (lazy) or umount -f (force) to release the mount point when the server is gone.

Introduction to autofs

autofs is a service that mounts NFS shares (and other filesystems) automatically when a user accesses them, and unmounts them after a period of inactivity.

  • NFS shares are mounted on demand — only when accessed
  • Shares are unmounted automatically after 5 minutes of inactivity (default)
  • If the NFS server is down, autofs simply returns "no such file or directory" — it does not hang the boot
  • autofs is the enterprise standard for home directory mounting in large organisations
  • No /etc/fstab entries are needed — autofs has its own configuration files
autofs vs fstab for NFS

Use /etc/fstab when the NFS share must always be mounted and the server is highly reliable. Use autofs when the share should be mounted on demand, when many mounts might be configured (e.g. home directories for many users), or when the server may not always be available.

Configuring autofs

autofs uses two levels of configuration: the master map defines mount points and points to map files; map files define the individual NFS shares.

# Step 1: Install autofs
$ sudo dnf install -y autofs

# Step 2: Edit the master map (/etc/auto.master)
$ cat /etc/auto.master
# Master map for autofs
/misc  /etc/auto.misc
/mnt   /etc/auto.mnt   --timeout=300
/net   -hosts

# Step 3: Create a map file (/etc/auto.mnt)
$ sudo vim /etc/auto.mnt
# Format: KEY  OPTIONS  SERVER:/EXPORT
data    -rw,sync,hard  servera:/exports/data
shared  -ro            servera:/exports/shared

# Step 4: Enable and start autofs
$ sudo systemctl enable --now autofs

# Step 5: Test — accessing the path triggers an automatic mount
$ ls /mnt/data           # this triggers the mount
$ mount | grep autofs   # confirm autofs mount

autofs Map Types

autofs supports indirect maps (a directory containing automounted subdirectories) and direct maps (specific absolute paths).

Indirect map (most common) — shares appear as subdirectories

# /etc/auto.master — indirect map mounted under /shares
/shares  /etc/auto.shares

# /etc/auto.shares — each key becomes /shares/KEY
data    -rw,sync  servera:/exports/data
logs    -ro       servera:/exports/logs
# Accessing /shares/data triggers mount of servera:/exports/data

Direct map — each share at its own absolute path

# /etc/auto.master — direct map
/-  /etc/auto.direct

# /etc/auto.direct — absolute paths as keys
/data      -rw,sync  servera:/exports/data
/var/share -ro       servera:/exports/shared
# Accessing /data triggers mount of servera:/exports/data
RHCSA exam typically tests indirect maps

The exam usually asks you to configure autofs so that accessing /BASEDIR/KEY automatically mounts SERVER:/EXPORT. This is an indirect map: /BASEDIR in the master map, KEY OPTIONS SERVER:/EXPORT in the map file.

autofs for Home Directories

A common exam scenario: mount user home directories from an NFS server automatically when users log in.

# Scenario: servera exports /home/ldapuser* via NFS
# Goal: /home/ldapuser1 on the client should automount from the server

# Step 1: Add to /etc/auto.master
/home  /etc/auto.home

# Step 2: Create /etc/auto.home
$ sudo vim /etc/auto.home
# The wildcard * matches any username; & substitutes the matched value
*  -rw,sync,hard  servera:/home/&
# When a user accesses /home/ldapuser1:
#   autofs mounts servera:/home/ldapuser1 at /home/ldapuser1

# Step 3: Reload autofs
$ sudo systemctl reload autofs

# Step 4: Test — access the home directory
$ ls /home/ldapuser1   # triggers the mount
$ mount | grep ldapuser

Troubleshooting NFS Mounts

NFS mount failures have several common causes — most are diagnosed with a systematic approach.

# Test 1: Can the client reach the server?
$ ping -c 3 servera
$ nc -z servera 2049    # test port 2049 is reachable (NFSv4)

# Test 2: Is the export available?
$ showmount -e servera

# Test 3: View NFS client errors in the journal
$ sudo journalctl -u autofs --since "10 minutes ago"
$ sudo journalctl -k | grep nfs   # kernel NFS messages

# Test 4: Check RPC services (NFSv3 only)
$ rpcinfo -p servera

# Test 5: Try verbose mount
$ sudo mount -v -t nfs servera:/exports/data /mnt/nfsdata
Error Likely cause
No route to hostNetwork connectivity or firewall blocking port 2049
Permission deniedClient IP not in the server's export access list
mount.nfs: access deniedServer's firewall or exports file rejects the client
Mount hangs indefinitelyHard mount to unreachable server; use umount -l -f

NFS Quick Reference

Task Command or configuration
Install NFS client toolssudo dnf install -y nfs-utils
List server's exportsshowmount -e SERVERNAME
Mount an NFS sharesudo mount -t nfs SERVER:/export /mnt/local
Mount read-onlysudo mount -t nfs -o ro SERVER:/export /mnt/local
Unmount NFS sharesudo umount /mnt/local
Unmount when server is downsudo umount -l -f /mnt/local
Persistent NFS fstab entrySERVER:/export /mnt nfs defaults,_netdev 0 0
Install autofssudo dnf install -y autofs
Enable and start autofssudo systemctl enable --now autofs
Reload autofs after config changesudo systemctl reload autofs
autofs master map/etc/auto.master or /etc/auto.master.d/
autofs indirect map entryKEY -OPTIONS SERVER:/export
autofs wildcard for home dirs* -rw,sync SERVER:/home/&
View NFS-related kernel messagessudo journalctl -k | grep nfs

Common Mistakes

Mistake What goes wrong Correct approach
Missing _netdev in fstab for NFS Boot hangs or NFS mount fails — network not ready when fstab is processed Always include _netdev in the options field for NFS fstab entries
Using fsck order 1 or 2 for NFS in fstab Boot attempts to run fsck on a network filesystem — fails or hangs NFS fstab entries always use 0 0 for dump and fsck order
Forgetting the colon in the NFS mount path mount servera/exports/data /mnt — treated as a local path mount servera:/exports/data /mnt — colon separates host from path
autofs map file has wrong format (missing dash before options) autofs fails to parse the map entry — share is not mounted Options in autofs map files must be prefixed with a dash: KEY -rw,sync SERVER:/path
Editing autofs config but not reloading the service Changes are not applied — old configuration still in effect Run sudo systemctl reload autofs after any map file change
Using /etc/fstab and autofs for the same mount point Both try to mount at the same path — conflicts and errors Use either fstab or autofs for a given mount point, never both

Knowledge Check

Answer these before moving to the next slide.

  1. Write the command to discover which NFS exports are available from a server named fileserver.
  2. Write the command to mount fileserver:/exports/apps at /apps using NFSv4 with read-write access.
  3. Write the /etc/fstab entry for the mount in question 2 to make it persistent. What two field values are always 0 for NFS?
  4. What does the _netdev fstab option do, and why is it required for NFS mounts?
  5. Write the autofs configuration (master map entry and map file entry) to make fileserver:/exports/apps automatically mount at /apps when accessed.
  6. Write the autofs wildcard map file entry that would automatically mount any user's home directory from fileserver:/home/USERNAME when they access /home/USERNAME.

Knowledge Check — Answers

  1. showmount -e fileserver — the -e flag lists all exported directories from the specified server.
  2. sudo mkdir -p /apps && sudo mount -t nfs fileserver:/exports/apps /apps
    NFSv4 is the default — no additional flags needed. For explicit NFSv4: sudo mount -t nfs4 fileserver:/exports/apps /apps
  3. fileserver:/exports/apps /apps nfs defaults,_netdev 0 0
    Both the dump field (5th) and the fsck order field (6th) are always 0 for NFS — the dump command cannot back up NFS, and fsck cannot check network filesystems.
  4. _netdev tells systemd to defer the mount until after the network is fully initialised. NFS requires the network to contact the server. Without _netdev, the system tries to mount the NFS share during early boot before the network interface is configured, causing the mount to fail or the boot to hang.
  5. In /etc/auto.master: /apps /etc/auto.apps
    In /etc/auto.apps: apps -rw,sync fileserver:/exports/apps
    Then: sudo systemctl enable --now autofs
  6. In /etc/auto.master: /home /etc/auto.home
    In /etc/auto.home: * -rw,sync,hard fileserver:/home/&
    The * matches any username; the & substitutes the matched name into the server path.

Key Takeaways

  1. NFS mount syntax: SERVER:/export as the device argument. Install nfs-utils. Use showmount -e SERVER to discover exports. Mount with sudo mount -t nfs SERVER:/export /mountpoint. Unmount with umount; use -l -f if the server is unreachable.
  2. fstab NFS entries always use _netdev and 0 0. _netdev defers the mount until the network is ready — without it, boot fails. The dump (field 5) and fsck order (field 6) are both 0 for NFS — neither dump nor fsck works on network filesystems.
  3. autofs mounts on demand and unmounts after inactivity. Configure the master map (/etc/auto.master) and a map file. Indirect map format: KEY -OPTIONS SERVER:/export. Reload after changes: sudo systemctl reload autofs.
  4. The wildcard pattern handles many users from one map entry. * -rw,sync SERVER:/home/& mounts any user's home directory on demand. The * matches any key; & substitutes the matched value into the server path.

Graded Lab

  • Install nfs-utils on the client. Use showmount -e to list the exports from your lab NFS server. Record the export path and confirm the client IP is allowed.
  • Create /mnt/nfsshare and mount the NFS export temporarily with sudo mount -t nfs. Verify with df -hT that the filesystem type shows as nfs4. Create a test file in the mount.
  • Unmount the share with sudo umount /mnt/nfsshare. Add a persistent fstab entry using _netdev and the correct 0 0 fields. Test with sudo mount -a and verify the test file is still accessible.
  • Install autofs. Add an entry to /etc/auto.master pointing /shares to a new map file /etc/auto.shares. Create the map file with an entry to mount the NFS export at /shares/nfsdata.
  • Enable and start autofs. Access /shares/nfsdata and confirm it is automatically mounted with mount | grep autofs. Wait 5 minutes and confirm the share is automatically unmounted.
  • Reboot the system. After reboot, confirm the fstab NFS mount is present at /mnt/nfsshare with df -hT, and that autofs is running and serves the /shares/nfsdata mount on demand.
RHCSA Objective

"Mount and unmount network file systems using NFS." Know showmount -e, mount -t nfs, the fstab entry with _netdev and 0 0, and autofs indirect map configuration with the wildcard home directory pattern.