Chapter Objective: Mount NFS and Samba/CIFS network shares manually and persistently, and configure autofs for on-demand mounting.
Key commands: showmount, mount -t nfs, autofs, mount -t cifs
Network Storage Protocols at a Glance
| Protocol | Typical Use |
|---|---|
| NFS (Network File System) | The standard for sharing storage between Linux/Unix systems |
| SMB/CIFS (Samba) | Interoperating with Windows file shares, or Linux systems serving Windows clients |
🔵 Why It Matters
Unlike the local storage in Chapters 10–11, network-attached storage depends on the network being available — which introduces a whole category of failure modes (server down, permissions on the server side, network path issues) that local disks don't have.
Mounting NFS Shares Manually
# Discover what an NFS server is exporting, before mounting anything
showmount -e nfsserver.example.com
# Create a mount point
sudo mkdir -p /mnt/nfsdata
# Mount an NFS export
sudo mount -t nfs nfsserver.example.com:/exports/data /mnt/nfsdata
# Confirm it mounted
df -h /mnt/nfsdata
# Unmount when done
sudo umount /mnt/nfsdata
✅ Tip — showmount -e First
Checking what a server actually exports before attempting to mount saves a round trip of guessing at the correct export path — and confirms the NFS server is reachable at all.
Persistent NFS Mounts with /etc/fstab
# /etc/fstab entry for an NFS mount
nfsserver.example.com:/exports/data /mnt/nfsdata nfs defaults 0 0
# Test it without rebooting, same as any fstab entry (Chapter 10)
sudo mount -a
⚠️ Warning — A Down NFS Server Can Hang Boot
An
/etc/fstab entry for an NFS share that's unreachable at boot time can cause the system to hang or delay significantly while waiting for the mount. Consider adding options like _netdev (wait for network) and reasonable timeout behavior, or use autofs instead for shares that aren't always essential at boot.
On-Demand Mounting with autofs
autofs mounts a network share automatically the moment it's accessed, and unmounts it again after a period of inactivity — avoiding the boot-time dependency risk of a permanent fstab entry, and saving resources for shares that aren't constantly in use.
# Install autofs if not already present
sudo dnf install autofs
# /etc/auto.master — maps a mount point prefix to a map file
/mnt/auto /etc/auto.mnt
# /etc/auto.mnt — the actual map, defining what mounts where
# key options location
data -fstype=nfs,rw nfsserver.example.com:/exports/data
# Enable and start the service
sudo systemctl enable --now autofs
# Accessing this path triggers the mount automatically
ls /mnt/auto/data
🔵 Note
With autofs, you never manually run
mount — simply accessing the path (like cd'ing into it or listing it) is what triggers the mount to happen, and it disappears again after being idle.
Mounting Samba/CIFS Shares
# Install the CIFS mount utilities if needed
sudo dnf install cifs-utils
# Mount a Windows/Samba share, prompting for a password
sudo mount -t cifs //fileserver.example.com/shared /mnt/winshare -o username=student
# Store credentials in a protected file instead of typing them each time
sudo mount -t cifs //fileserver.example.com/shared /mnt/winshare -o credentials=/etc/samba/creds
# /etc/fstab entry using a credentials file
//fileserver.example.com/shared /mnt/winshare cifs credentials=/etc/samba/creds 0 0
⚠️ Warning — Protect the Credentials File
A credentials file contains a plaintext username and password. Restrict its permissions tightly (
chmod 600, owned by root) — anyone who can read it can authenticate as that account against the share.
Troubleshooting Network Storage
# Confirm basic network reachability to the server
ping nfsserver.example.com
# Confirm the export is actually visible
showmount -e nfsserver.example.com
# Check what's currently mounted, and how
mount | grep nfs
# Check recent kernel/service messages related to the mount
journalctl -xe | grep -i nfs
| Symptom | Likely Cause |
|---|---|
| Mount hangs indefinitely | Server unreachable, or firewall blocking the required ports |
| "Permission denied" after mounting | Server-side export permissions or client UID/GID mismatch |
| Mount succeeds but disappears later | autofs idle timeout (expected) vs. an unexpected disconnect (not expected) |
✅ Tip — Separate "Can't Reach It" from "Reached It, Denied"
A hanging mount and a "permission denied" mount point to very different problems — the first is almost always network/firewall, the second is almost always server-side export configuration or user/group mapping. Diagnose accordingly rather than guessing.
Key Terms for Chapter 15
- NFS
- Network File System; the standard protocol for sharing storage between Linux/Unix systems
- export
- A directory an NFS server makes available for clients to mount
- showmount
- Queries an NFS server to list what it currently exports
- autofs
- Service that mounts network shares on demand and unmounts them after idle time
- SMB/CIFS
- The protocol used by Windows and Samba file shares
- credentials file
- A protected file storing a username/password for mounting a CIFS share without typing them interactively
Review Questions
- What command lets you check what an NFS server is exporting before attempting to mount anything?
- Why can a permanent
/etc/fstabentry for an NFS share be risky at boot time if the server is unreachable? - What problem does autofs solve compared to a static fstab entry for a network share?
- Why should a CIFS credentials file have restricted permissions?
- A network share mount hangs indefinitely with no error. What's the most likely category of problem?
- A network share mounts successfully, but every file access returns "permission denied." What's the most likely category of problem this time?
- Write a command that mounts a Samba share at
//fileserver.example.com/sharedonto/mnt/winshareusing a credentials file at/etc/samba/creds.