Operations 10 min read

Master NFS: Configure, Manage, and Optimize Network File Systems on Linux

Learn how to configure and manage NFS on Linux, covering its architecture, required packages, export file syntax, common options, essential tools like rpcinfo and exportfs, mounting techniques, and a step‑by‑step autofs deployment example.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master NFS: Configure, Manage, and Optimize Network File Systems on Linux

NFS Overview

Network File System (NFS) 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 Remote Procedure Call (RPC) in a client‑server model.

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

NFS Software Packages

Package: nfs-utils (includes 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 assigned by portmap (111)
Key NFS daemons:
  rpc.nfsd   – main NFS daemon, controls client access
  rpc.mountd – handles mount/unmount and permission management
  rpc.lockd  – optional, manages file locking
  rpc.statd – optional, checks and repairs file consistency
Log directory: /var/lib/nfs/
Configuration files: /etc/exports, /etc/exports.d/*.exports

NFS Export File Format

/dir  host1(opt1,opt2)  host2(opt1,opt2) …

Lines beginning with # are comments. Host specifications can be: * – wildcard for all clients

IPv4, IPv6, or FQDN

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

Wildcards in hostnames (e.g., *.example.com) – not allowed for IPs

Netgroups: @group_name Typical 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 since NFS 1.0, safer)
root_squash           – maps remote root to uid 65534 (nfsnobody)
no_root_squash        – remote root retains root privileges
all_squash            – maps all remote users to anonymous uid/gid
no_all_squash         – preserves original uid/gid
anonuid, anongid      – map anonymous user to specific uid/gid

Example Export 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 Tools

rpcinfo – displays RPC program information.

rpcinfo -p hostname   # list registered RPC services
rpcinfo -s hostname   # show registered programs

exportfs

Manages NFS exports.

-v   # show all NFS shares on the local host
-r   # re‑read the export file and share directories
-a   # list all current exports
-au  # unexport all shares

showmount

Shows NFS shares on a remote host.

# showmount -e hostname

mount.nfs (Client Mount)

Common mount options (see man 5 nfs):

fg          # foreground mount (default)
bg          # background mount
hard        # keep trying on failure (default)
soft        # fail after timeout
intr        # allow interrupting hard mounts
rsize/wsize # max bytes per read/write (default 32768)
_netdev     # do not mount until network is up
vers=4.2    # specify NFS version (CentOS 8 defaults to 4.2)

Security‑oriented recommendation: use nosuid,netdev,noexec options.

Mount Examples

# Temporary mount
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

Practical Case: Setting Up NFS with autofs

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

# On first client (relative‑path autofs)
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 mount
su - user1
df -T /home/user1

# On second client (absolute‑path autofs)
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
su - user1
df -T /home/user1
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.

RPCNFSFilesystemMountingautofs
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.