Operations 10 min read

Mastering NFS on CentOS: From Installation to Autofs Integration

This guide explains what NFS (Network File System) is, its advantages, required packages, configuration file syntax, export options, essential tools like rpcinfo, exportfs, showmount and mount.nfs, and provides step‑by‑step examples for mounting, fstab entries, and integrating autofs on CentOS systems.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering NFS on CentOS: From Installation to Autofs Integration

NFS (Network File System) is a kernel‑based file system developed by Sun Microsystems that allows users and programs to access remote files as if they were local, using RPC (Remote Procedure Call) in a client‑server model.

Advantages of NFS include saving local storage space by placing frequently used directories such as /home on a central server, which can be accessed over the network.

NFS Software Packages

software package: nfs-utils   # provides server and client tools (not installed by default on minimal CentOS 8)
related packages: rpcbind (required), tcp_wrappers
kernel module: nfs.ko
ports: 2049 (nfsd), other ports allocated by portmap (111)

NFS service processes:
  rpc.nfsd   – main NFS daemon, manages client access
  rpc.mountd – handles mount/unmount requests and permission checks
  rpc.lockd  – optional, manages file locking
  rpc.statd  – optional, checks file consistency

Configuration files:
  /etc/exports
  /etc/exports.d/*.exports

Export File Syntax

Each line in /etc/exports follows the format: /dir host1(opt1,opt2) host2(opt1,opt2) ... Lines starting with # are comments. Host specifications can be: * – wildcard for all clients

IPv4, IPv6, or FQDN

IP networks in CIDR or netmask notation (e.g., 172.31.0.0/16)

Wildcards for hostnames (e.g., *.example.com)

NIS netgroups (e.g., @group_name)

Common export options (default (ro,sync,root_squash,no_all_squash)): ro / rw – read‑only or read‑write async – asynchronous writes (higher performance, lower safety) sync – synchronous writes (default, safer) root_squash – map remote root to nfsnobody (UID 65534) no_root_squash – keep remote root privileges all_squash – map all remote users to

nfsnobody
no_all_squash

– preserve UID/GID of remote users anonuid / anongid – map anonymous users to specific UID/GID

Example /etc/exports Entries

/myshare server.example.com
/myshare *.example.com
/myshare server?.example.com
/myshare server[0-20].example.com
/myshare 172.25.11.10
/myshare 172.25.0.0/16
/myshare 2000:472:18:b51:c32:a21
/myshare 2000:472:18:b51::/64
/myshare *.example.com 172.25.0.0/16
/myshare desktop.example.com(ro)
/myshare desktop.example.com(ro) server[0-20].example.com(rw)
/myshare diskless.example.com(rw,no_root_squash)

NFS Management Tools

rpcinfo – displays RPC program registrations.

rpcinfo -p               # list local RPC services
rpcinfo -s hostname      # show registered programs on a remote host

exportfs – manages exported file systems.

-v   # show all current NFS exports
-r   # re‑read /etc/exports and apply changes
-a   # list all exports
-au  # stop all exports

showmount – lists NFS shares on a remote host.

# showmount -e hostname

Mounting NFS Shares

Typical mount options (see man 5 nfs) include: fg / bg – foreground or background mount hard / soft – request behavior intr – allow interrupting a hard mount rsize / wsize – max bytes per read/write (default 32768) _netdev – defer mount until network is up vers – NFS protocol version (CentOS 8 defaults to 4.2)

Temporary mount example:

# mount -o rw,nosuid,fg,hard,intr 172.31.0.8:/testdir /mnt/nfs/

Persistent mount via /etc/fstab:

172.16.0.1:/public  /mnt/nfs  nfs  defaults,_netdev 0 0

Integrating Autofs

On the NFS server (CentOS 8) create a user and export its home directory:

# mkdir -pv /data/home
# useradd -d /data/home/user1 -u 2000 user1
# echo "/data/home *(rw)" > /etc/exports.d/test.exports
# exportfs -r

On a client (CentOS 7) configure autofs for relative paths:

# useradd -M -u 2000 user1
# echo "/home /etc/auto.home" >> /etc/auto.master
# echo "* -fstype=nfs,vers=3 172.31.0.8:/data/home/&" > /etc/auto.home
# systemctl restart autofs

Verify the mount:

# su - user1
$ pwd
/home/user1
$ df -T /home/user1

For an absolute‑path autofs setup on another client (CentOS 6):

# useradd -M -u 2000 user1
# echo "/- /etc/auto.home" >> /etc/auto.master
# echo "/home/user1 -fstype=nfs,vers=3 nfsserver:/data/home/user1" > /etc/auto.home
# service autofs restart

After logging in as user1, the home directory is mounted from the NFS server, and df -T confirms the NFS type.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

RPCLinuxNFSFilesystemCentOSautofs
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.