RED HAT ENTERPRISE LINUX

NFS & Automounter

Accessing Network-Attached Storage

CIS238RH | RHEL System Administration 2
Mesa Community College

Learning Objectives

1
Understand NFS concepts

How NFS works, exports, clients, and versions

2
Mount NFS shares manually

Use mount command and /etc/fstab for persistent mounts

3
Configure the automounter (autofs)

Set up on-demand mounting with master and map files

4
Troubleshoot NFS access issues

Diagnose connectivity, permissions, and mount problems

What is NFS?

Network File System (NFS) is a distributed filesystem protocol that allows clients to access files over a network as if they were on local storage. Developed by Sun Microsystems, it is the standard for Unix/Linux file sharing.

NFS Server
Exports /shared
Network
NFS Protocol
NFS Client
Mounts to /mnt/data

Server (Exports)

Shares directories for remote access. Controls who can connect and what permissions they have.

Client (Mounts)

Connects to server exports and mounts them locally. Users access files transparently.

NFS Versions

VersionFeaturesStatus
NFSv3 Stateless, UDP/TCP, widely compatible Legacy, still supported
NFSv4 Stateful, TCP only, single port (2049), built-in security Current default in RHEL
NFSv4.1 Parallel NFS (pNFS), session trunking Supported, enterprise features
NFSv4.2 Server-side copy, sparse files, space reservation Latest, RHEL 8/9 default
# Check which NFS version is being used
[root@client ~]# nfsstat -m
/mnt/data from server:/export
 Flags: rw,relatime,vers=4.2,rsize=1048576,wsize=1048576...

# Force specific version when mounting
[root@client ~]# mount -t nfs -o vers=4.2 server:/export /mnt/data
[root@client ~]# mount -t nfs -o nfsvers=3 server:/export /mnt/legacy
RHEL default: NFSv4.2 is the default in RHEL 8 and 9. It uses only TCP port 2049, simplifying firewall configuration compared to NFSv3.

Discovering Exports

Before mounting, you need to know what the server exports. Use showmount to query available exports from an NFS server.

# List exports from an NFS server
[root@client ~]# showmount -e nfsserver.example.com
Export list for nfsserver.example.com:
/export/data    192.168.1.0/24
/export/home    *.example.com
/export/public  *

# Install nfs-utils if showmount not found
[root@client ~]# dnf install nfs-utils

# Show clients currently mounting from a server
[root@client ~]# showmount -a nfsserver.example.com
All mount points on nfsserver.example.com:
192.168.1.100:/export/data
192.168.1.101:/export/home

# NFSv4 note: showmount may not work with NFSv4-only servers
# NFSv4 uses different discovery mechanism
NFSv4 note: showmount uses NFSv3 protocol. Pure NFSv4 servers may not respond. Try mounting the root export (server:/) and browsing.

Manual Mounting

Use the mount command to immediately attach an NFS export to your filesystem. This is temporary - the mount is lost on reboot.

mount -t nfs [options] server:/export /mountpoint
# Basic NFS mount
[root@client ~]# mount -t nfs server:/export/data /mnt/data

# Create mount point if it does not exist
[root@client ~]# mkdir -p /mnt/data
[root@client ~]# mount -t nfs server:/export/data /mnt/data

# Verify the mount
[root@client ~]# mount | grep nfs
server:/export/data on /mnt/data type nfs4 (rw,relatime,vers=4.2...)

[root@client ~]# df -h /mnt/data
Filesystem           Size  Used Avail Use% Mounted on
server:/export/data   50G   10G   40G  20% /mnt/data

# Access files
[root@client ~]# ls /mnt/data
file1.txt  file2.txt  project/

Mount Options

# Read-write mount (default)
[root@client ~]# mount -t nfs -o rw server:/export /mnt/data

# Read-only mount
[root@client ~]# mount -t nfs -o ro server:/export /mnt/readonly

# Specify NFS version
[root@client ~]# mount -t nfs -o vers=4.2 server:/export /mnt/data

# Soft mount with timeout (returns error if server unavailable)
[root@client ~]# mount -t nfs -o soft,timeo=30 server:/export /mnt/data

# Hard mount (default - keeps retrying forever)
[root@client ~]# mount -t nfs -o hard server:/export /mnt/data

# Background mount (useful in fstab - does not block boot)
[root@client ~]# mount -t nfs -o bg server:/export /mnt/data

# Combined options
[root@client ~]# mount -t nfs -o rw,vers=4.2,soft,timeo=30 server:/export /mnt/data
OptionDescription
rw / roRead-write or read-only access
hard / softRetry forever (hard) or return error (soft) if server down
bgBackground retry if initial mount fails
timeo=NTimeout in tenths of seconds
vers=NNFS version (3, 4, 4.1, 4.2)
sec=MODESecurity mode (sys, krb5, krb5i, krb5p)

Persistent Mounts: /etc/fstab

Add entries to /etc/fstab for NFS mounts that should persist across reboots. The system mounts these automatically during boot.

# /etc/fstab format:
# device              mountpoint    type  options         dump pass

# Basic NFS mount in fstab
server:/export/data   /mnt/data     nfs   defaults        0    0

# With recommended options
server:/export/data   /mnt/data     nfs   rw,bg,soft      0    0

# Read-only mount
server:/export/docs   /mnt/docs     nfs   ro,bg           0    0

# Home directories with specific version
nfs.example.com:/home /home         nfs   rw,bg,vers=4.2  0    0

# Test fstab entry without rebooting
[root@client ~]# mount /mnt/data
# Or mount all fstab entries
[root@client ~]# mount -a
Always test! After editing fstab, run mount -a to test. A bad fstab entry can prevent the system from booting properly.

Unmounting NFS

# Unmount an NFS share
[root@client ~]# umount /mnt/data

# If busy, find what is using it
[root@client ~]# umount /mnt/data
umount: /mnt/data: target is busy.

[root@client ~]# fuser -mv /mnt/data
                     USER        PID ACCESS COMMAND
/mnt/data:           root     kernel mount /mnt/data
                     alice      1234 ..c.. bash
                     alice      1235 ..c.. vim

# Options when busy:
# 1. Close applications using the mount
# 2. Change directory away from mount
# 3. Lazy unmount (detach now, cleanup when idle)
[root@client ~]# umount -l /mnt/data

# 4. Force unmount (may cause data loss!)
[root@client ~]# umount -f /mnt/data

# Show all NFS mounts
[root@client ~]# mount -t nfs,nfs4
Caution: Force unmount (-f) can cause data loss if there are pending writes. Use only when necessary.

The Automounter

autofs (automounter) mounts NFS shares on-demand when accessed and unmounts them after a period of inactivity. This reduces server load and improves reliability.

Manual/fstab Mounts

Always connected
Uses server resources continuously
Boot fails if server unavailable
Good for always-needed storage

Automounter (autofs)

Mounts on access
Unmounts after idle timeout
Boot succeeds without server
Good for home dirs, optional shares

# Install autofs
[root@client ~]# dnf install autofs

# Enable and start the service
[root@client ~]# systemctl enable --now autofs

Autofs Architecture

/etc/auto.master
Master map
/etc/auto.misc
Map file
Mount on access
# Master map: /etc/auto.master (or /etc/auto.master.d/*.autofs)
# Format: mountpoint    map-file    [options]
/misc    /etc/auto.misc
/home    /etc/auto.home

# Map file: /etc/auto.misc
# Format: key    [options]    server:/export
data     -rw,soft    server:/export/data
docs     -ro         server:/export/docs

# Result: accessing /misc/data triggers mount of server:/export/data
How it works: The master map defines base directories and points to map files. Map files define what gets mounted under each base directory. Access triggers mount.

Direct vs Indirect Maps

Indirect Maps

Mount point is base directory + key

# auto.master
/data   /etc/auto.data

# auto.data
projects  server:/export/proj
archive   server:/export/archive

# Results in:
# /data/projects
# /data/archive

Direct Maps

Mount point is the full path (key)

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

# auto.direct
/mnt/data     server:/export/data
/opt/shared   server:/export/shared

# Results in:
# /mnt/data
# /opt/shared
When to use: Indirect maps for organizing multiple mounts under one directory (home dirs, project shares). Direct maps for specific paths that cannot be reorganized.

Configuring Indirect Maps

# Step 1: Edit master map - add entry for /shares base directory
[root@client ~]# vi /etc/auto.master.d/shares.autofs
/shares    /etc/auto.shares

# Step 2: Create the map file
[root@client ~]# vi /etc/auto.shares
data       -rw,soft,timeo=30    nfsserver:/export/data
documents  -ro                   nfsserver:/export/docs
projects   -rw                   nfsserver:/export/projects

# Step 3: Reload autofs to pick up changes
[root@client ~]# systemctl reload autofs

# Step 4: Test - just access the directory!
[root@client ~]# ls /shares/data
file1.txt  file2.txt  subdir/

# Check that it mounted
[root@client ~]# mount | grep shares
nfsserver:/export/data on /shares/data type nfs4 ...

# After 5 minutes idle, it auto-unmounts

Configuring Direct Maps

# Step 1: Create direct map entry in master map
[root@client ~]# vi /etc/auto.master.d/direct.autofs
/-    /etc/auto.direct

# Step 2: Create direct map file with full paths
[root@client ~]# vi /etc/auto.direct
/mnt/nfsdata       -rw,soft    nfsserver:/export/data
/opt/shared        -ro         nfsserver:/export/shared
/var/log/remote    -ro         logserver:/logs

# Step 3: Create the mount point directories
[root@client ~]# mkdir -p /mnt/nfsdata /opt/shared /var/log/remote

# Step 4: Reload autofs
[root@client ~]# systemctl reload autofs

# Step 5: Test
[root@client ~]# ls /mnt/nfsdata
file1.txt  file2.txt

[root@client ~]# ls /var/log/remote
server1.log  server2.log
Note: For direct maps, the mount point directories must exist. autofs does not create them automatically like it does for indirect maps.

Automounting Home Directories

Automounting home directories is a common use case. Users get their home mounted when they log in, unmounted when idle. The wildcard * handles any username.

# Master map entry for home directories
[root@client ~]# vi /etc/auto.master.d/home.autofs
/home    /etc/auto.home

# Map file using wildcard for any user
[root@client ~]# vi /etc/auto.home
*    -rw    nfsserver:/home/&

# The * matches any username
# The & substitutes the matched key (username)
# /home/alice -> nfsserver:/home/alice
# /home/bob   -> nfsserver:/home/bob

# Reload and test
[root@client ~]# systemctl reload autofs
[root@client ~]# su - alice
[alice@client ~]$ pwd
/home/alice
Wildcard: The * matches any key. The & in the source substitutes that matched value. Together they handle unlimited users with one line.

Autofs Options

# Default timeout is 300 seconds (5 minutes)
# Change in /etc/autofs.conf or /etc/sysconfig/autofs
[root@client ~]# vi /etc/autofs.conf
timeout = 600    # 10 minutes

# Or set per-mount timeout in map file
data    -rw,soft,--timeout=120    server:/export/data

# Browse mode - show directories before mounting
# In auto.master:
/shares    /etc/auto.shares    --browse

# Now ls /shares shows entries without mounting them
[root@client ~]# ls /shares
data  documents  projects

# Check autofs status and mounts
[root@client ~]# systemctl status autofs
[root@client ~]# automount -m    # Show configured maps
Browse mode: The --browse option creates ghost directories so ls shows available mounts without triggering them. Actual mount happens on access.

Troubleshooting NFS

# Check if NFS server is reachable
[root@client ~]# ping nfsserver
[root@client ~]# showmount -e nfsserver

# Check NFS client services
[root@client ~]# systemctl status nfs-client.target

# Test mount manually first
[root@client ~]# mount -t nfs nfsserver:/export/data /mnt/test
# If this fails, autofs will fail too

# Check firewall (client needs outbound to 2049)
[root@client ~]# firewall-cmd --list-all
# Server needs to allow port 2049/tcp inbound

# Verbose mount for debugging
[root@client ~]# mount -t nfs -v nfsserver:/export/data /mnt/test

# Check RPC services
[root@client ~]# rpcinfo -p nfsserver

# SELinux - check for denials
[root@client ~]# ausearch -m avc -ts recent | grep nfs

Troubleshooting Autofs

# Check autofs service status
[root@client ~]# systemctl status autofs
● autofs.service - Automounts filesystems on demand
     Active: active (running)

# View autofs logs
[root@client ~]# journalctl -u autofs

# Enable verbose logging
[root@client ~]# vi /etc/sysconfig/autofs
LOGGING="verbose"
[root@client ~]# systemctl restart autofs

# Check map configuration
[root@client ~]# automount -m
autofs dump map information
...
/shares:
  data | -rw,soft | nfsserver:/export/data

# Common issues:
# - Typo in map file syntax
# - Missing reload after config change
# - Base directory owned by wrong user
# - Underlying NFS issue (test with manual mount)

# Force expire (unmount) all autofs mounts
[root@client ~]# automount -f

Security Considerations

NFS traditionally relies on IP-based trust. Any root user on a trusted client appears as root on the NFS server unless precautions are taken.

# Server-side export options (on NFS server)
/export/data    192.168.1.0/24(rw,sync,root_squash)

# root_squash (default): remote root -> nobody user
# no_root_squash: remote root stays root (dangerous!)
# all_squash: all remote users -> nobody

# Client mount with Kerberos security
[root@client ~]# mount -t nfs -o sec=krb5p server:/export /mnt/secure

# sec options:
# sec=sys     - Standard Unix auth (default)
# sec=krb5    - Kerberos authentication
# sec=krb5i   - Kerberos with integrity checking
# sec=krb5p   - Kerberos with privacy (encryption)
Enterprise environments: Use NFSv4 with Kerberos (krb5p) for authenticated and encrypted NFS in security-sensitive environments.

Best Practices

Do

  • Use autofs for home directories and optional shares
  • Use fstab with bg option for always-needed mounts
  • Test fstab entries with mount -a before reboot
  • Use NFSv4 unless legacy compatibility required
  • Verify exports with showmount before troubleshooting
  • Use soft mounts for non-critical data
  • Document NFS dependencies for applications
  • Monitor NFS performance in production

Do Not

  • Use hard mounts without bg in fstab (boot hangs)
  • Skip testing after configuration changes
  • Use no_root_squash in production
  • Mix autofs and manual management of same path
  • Forget to reload autofs after map changes
  • Force unmount unless absolutely necessary
  • Assume NFS works without testing connectivity
  • Ignore timeout tuning for your workload
Rule of thumb: Use autofs for user-facing shares (home dirs, project folders). Use fstab for system-level persistent storage that applications depend on.

Key Takeaways

1

NFS Basics: Server exports directories, clients mount them. Use showmount -e to discover exports.

2

Manual Mounting: mount -t nfs server:/export /mnt. Use /etc/fstab with bg option for persistent mounts.

3

Automounter: Configure in /etc/auto.master and map files. Use wildcards (* and &) for home directories.

4

Troubleshooting: Test NFS manually first. Check connectivity, firewall, and autofs logs. Reload autofs after changes.

LAB EXERCISES

  • Mount an NFS share manually and verify access
  • Add persistent NFS mount to /etc/fstab with appropriate options
  • Configure autofs indirect map for shared directories
  • Set up autofs wildcard map for home directories
  • Configure autofs direct map for specific paths
  • Troubleshoot a failing NFS mount (connectivity, exports, autofs)

Next: Installing Red Hat Enterprise Linux