Configure autofs for on-demand NFS mounting
autofs, also called automount, is the Linux automounter daemon that mounts an NFS network filesystem when a user accesses it. This on-demand approach avoids mounting every shared directory during boot, reduces unnecessary network traffic and simplifies administration of frequently used resources. It is particularly useful for project directories and centrally managed home directories.
The examples below follow RHEL, CentOS Stream and Fedora conventions. Australian IT teams often combine Red Hat subscriptions, CentOS Stream rebuilds and Fedora evaluation hosts, so package and service names should still be checked before deployment. For a Sydney or Melbourne server room, test one non-critical share first and keep NFS traffic on a local data-centre network rather than an ordinary internet connection. Give it a spin in the lab before rolling it into production.
Prepare the NFS export
On the NFS server, install the utilities and create the shared directory. The server must be running before client systems can trigger a mount.
sudo dnf install nfs-utils
sudo systemctl enable --now nfs-server
sudo mkdir -p /srv/nfs/projects
For NFSv4, export /srv/nfs as the pseudo-root and make its subdirectories available through crossmnt. Replace the example client network with the addresses permitted to access the share.
echo '/srv/nfs 192.0.2.0/24(rw,sync,no_subtree_check,fsid=0,root_squash,crossmnt)' | sudo tee -a /etc/exports
sudo exportfs -rav
sudo exportfs -v
root_squash maps client root to an unprivileged account. Directory ownership and permissions must therefore permit the intended users. On a firewalld system, allow the NFS service and reload the firewall. SELinux-enforcing servers may also need an nfs_t file-context rule.
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload
sudo semanage fcontext -a -t nfs_t '/srv/nfs(/.*)?'
sudo restorecon -Rv /srv/nfs
Mixed NFSv3 clients require access to rpcbind and mountd, whereas NFSv4 normally uses TCP port 2049 directly.
Create the automount maps
Install autofs on each client. The master map points to a map file containing the NFS location, while the key inside that file becomes a directory beneath the mount point.
sudo dnf install autofs nfs-utils
sudo mkdir -p /mnt/nfs
echo 'projects -fstype=nfs4,rw,hard,timeo=600,retrans=2,timeout=60 192.0.2.10:/projects' | sudo tee /etc/auto.nfs
echo '/etc/auto.nfs /mnt/nfs' | sudo tee -a /etc/auto.master
sudo systemctl enable --now autofs
Here, projects is the automount key, so its final path is /mnt/nfs/projects. The server-side NFSv4 path is /projects because /srv/nfs was exported as the pseudo-root.
The access model is comparable to live dealer games: the table is presented immediately, while a session starts after the user selects it. With autofs, the trigger is a filesystem lookup. Listing the parent directory shows the key, but entering /mnt/nfs/projects causes the client to contact the server and mount the share. Restart autofs after editing either map.
Trigger and verify the mount
Test the path directly rather than assuming the mount has started. The first access can take a moment because autofs must locate the map, contact the NFS server and establish the connection.
ls -la /mnt/nfs/projects
findmnt -t nfs4,nfs
nfsstat -m
df -hT /mnt/nfs/projects
A successful findmnt result should show the NFSv4 source, mount point and active options. nfsstat -m provides server statistics and can reveal stale connections or repeated timeouts.
If access fails, watch both the autofs service and kernel messages while trying the path again. A map typo often produces “No such file or directory,” while an unreachable server or refused export produces a timeout or access-denied message.
journalctl -u autofs -f
journalctl -k -f
systemctl status autofs
Tune reliability and security
A hard mount keeps retrying a temporarily unavailable server, which protects writes but can leave an application waiting indefinitely. A soft mount returns an I/O error after its timeout, but that behaviour can cause application failures or corruption when writes are in progress. For dependable storage, use hard with redundant servers and test the failure behaviour.
The example timeo=600 value means 60 seconds before a retransmission, while timeout=60 allows the indirect map to become idle. Adjust these values for local latency and workload. NFS across widely separated Perth or Brisbane branches needs an appropriate WAN architecture, caching and tested recovery procedures; simply increasing a timeout is not a substitute for resilient storage.
Plain sec=sys NFS relies on numeric user and group IDs. Use consistent identities through LDAP or SSSD, or mount with sec=krb5p where Kerberos is already available. NFS traffic is not encrypted merely because NFSv4 is used, so restrict exports to approved source networks and consider encrypted transport for sensitive data. Australian data-residency requirements may also require exports and backups to remain within approved regions.
Troubleshoot and recover
Common problems include stale mounts, incorrect server paths, refused client addresses, mismatched UID mappings and SELinux denials. “Transport endpoint is not connected” usually indicates a stale NFS mount. Unmount the affected hierarchy, clear the automount cache and restart the service before testing again.
sudo automount -uc /mnt/nfs
sudo automount -f
sudo systemctl restart autofs
For host replacement, the bare-metal restore workflow provides a practical sequence for copying data and rebuilding disks. After restoration, check /etc/exports, /etc/auto.master, /etc/auto.nfs, package state, firewall rules, SELinux labels and the enabled status of autofs and nfs-server.
Keep secured copies of the export and map files with the server’s configuration backup. They contain the information needed to reconstruct access quickly after disk replacement, account changes or a migration between data-centre sites.
autofs does not distribute files or replace the NFS server; it only controls when a configured export is mounted. The NFS service, export permissions, identities and network path still determine whether users can read or write data.
Remember that reliable on-demand mounting depends on an explicit export, a minimal automount map, tested first access and suitable timeout and security settings.