Operations 10 min read

Mastering NFS: How to Configure Network File System on Linux

Learn the fundamentals of NFS (Network File System) on Linux, including its architecture, advantages, required packages, configuration files, export options, essential commands like rpcinfo, exportfs, showmount, and step‑by‑step examples for setting up NFS servers and clients with autofs.

Raymond Ops
Raymond Ops
Raymond Ops
Mastering NFS: How to Configure Network File System on Linux

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 commonly used data such as the /home directory on an NFS server, which can be accessed over the network.

NFS Software Overview

Software package: nfs-utils (includes server and client tools; not installed by default on minimal CentOS 8)
Related packages: rpcbind (required), tcp_wrappers
Kernel support: nfs.ko
Ports: 2049 (nfsd), other ports allocated by portmap (111)
Main NFS processes:
  rpc.nfsd      – primary NFS daemon, manages client access
  rpc.mountd    – handles mounting/unmounting 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 sharing configuration file format: /dir host1(opt1,opt2) host2(opt1,opt2)... Format notes:

Lines starting with # are comments.

Host specifications can be:

anonymous – represented by * to match all clients

Single host – IPv4, IPv6, or FQDN

IP networks – both CIDR and netmask styles are supported (e.g., 172.31.0.0/255.255.0.0 or 172.31.0.0/16)

Wildcards – hostname patterns such as *.example.com (IP wildcards are not allowed)

Netgroups – NIS domain groups, prefixed with @

Default export options: (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 after NFS 1.0, safer but slower)

root_squash – maps remote root to nfsnobody (UID 65534)

no_root_squash – preserves remote root UID

all_squash – maps all remote users to anonymous UID/GID

no_all_squash – keeps original UID/GID

anonuid / anongid – specify custom anonymous UID/GID

Example NFS export configuration:

/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 on a host. rpcinfo -p hostname Shows registered RPC services and their ports.

exportfs

Manages NFS exported file systems.

-v   # view all NFS shares on the local machine
-r   # re‑read configuration files and export directories
-a   # list all current exports
-au  # stop all local exports

showmount

Displays NFS shares on a remote host.

# showmount -e hostname

mount.nfs (client mounting)

Common mount options (see man 5 nfs):

fg – foreground mount (default)

bg – background mount

hard – persistent requests (default)

soft – non‑persistent requests

intr – allows interruption of hard mounts

rsize / wsize – maximum bytes per read/write (default rsize=32768)

_netdev – do not mount until network is available

vers – specify NFS version (CentOS 8 defaults to 4.2, CentOS 7 to 4.1, CentOS 6 to 4.0)

Example temporary mount:

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

Example entry for automatic mounting at boot (in /etc/fstab):

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

Case Study: Step‑by‑Step Setup

# On the NFS server, create a user and home directory to share
mkdir -pv /data/home
useradd -d /data/home/user1 -u 2000 user1
# Define export (e.g., /etc/exports.d/test.exports)
/data/home *(rw)
exportfs -r
# On client 1 (172.31.0.7) configure autofs for relative paths
vim /etc/auto.master
/home /etc/auto.home
vim /etc/auto.home
* -fstype=nfs,vers=3 172.31.0.8:/data/home/&
systemctl restart autofs
# Verify mount
df -T /home/user1
# On client 2 (172.31.0.6) configure autofs for absolute paths
vim /etc/auto.master
/- /etc/auto.home
vim /etc/auto.home
/home/user1 -fstype=nfs,vers=3 nfsserver:/data/home/user1
service autofs restart
# Verify mount
df -T /home/user1

These steps demonstrate creating NFS exports, reloading the configuration, and using autofs on multiple clients to automatically mount user home directories.

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.

RPClinuxNFSMountNetwork File Systemautofs
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

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.