Home Blog Certs Knowledge Base About

LPIC-2 209.2 โ€” NFS Server Configuration

Exam topic 209.2 โ€” NFS Server Configuration (weight: 3). Covers NFSv3 setup, /etc/exports configuration, NFS utilities, client-side mounting, and access control. LPIC-2 focuses on NFSv3.


What Is NFS

NFS (Network File System) is a protocol for mounting remote filesystems as local ones. The server publishes (exports) a directory; the client mounts it via the standard mount command.


NFS Versions

VersionYearProtocolFeatures
NFSv21989UDP only32-bit files, deprecated
NFSv31995UDP or TCP64-bit files, async write, weak cache consistency
NFSv42000/2015TCP (primary)Kerberos, single port 2049, built-in locking

NFSv3 uses RPC (Remote Procedure Call) for mounting, locking, and quotas โ€” requiring multiple ports, which complicates firewall configuration.

# Disable NFSv4 on Red Hat โ€” /etc/sysconfig/nfs
RPCNFSDARGS='--no-nfs-version 4'

# Debian โ€” /etc/default/nfs-kernel-server
# add --no-nfs-version 4 to RPCMOUNTDOPTS

# Force NFSv3 on mount
mount -o vers=3 server:/share /mnt

Architecture and Daemons

NFSv3 operates via a set of daemons and kernel services, all registered through the portmapper.

DaemonAliasRoleWhere needed
rpc.nfsd / nfsdnfsdMain NFS daemon, data transferServer
rpc.mountdmountdHandles mount requestsServer
rpcbindportmapperMaps RPC services to portsServer and client
rpc.lockdlockdNLM protocol, file lockingBoth (not needed in NFSv4)
rpc.statdstatdState monitoring, lock recoveryBoth
rpc.rquotadrquotadQuota management on exportsServer
idmapdrpc.idmapdUID/GID mapping by nameNFSv4 only
# Start NFS (CentOS/RHEL)
systemctl start nfs rpcbind

# Start NFS (Debian/Ubuntu)
systemctl start nfs-kernel-server rpcbind

On kernel-space NFS systems, the server appears in the process list as [nfsd]. On older user-space NFS systems โ€” as rpc.nfsd.


/etc/exports

The main NFS server configuration file. Each line is one entry:

/path/to/directory  client(options)  client2(options)

Additional .exports files can be placed in /etc/exports.d/.

Client specification formats:

TypeExampleDescription
Single host192.168.1.10 or client.example.comSingle IP or FQDN
Subnet192.168.1.0/24 or 192.168.1.0/255.255.255.0CIDR or mask
Wildcard192.168.56.*IP wildcard (use carefully)
Domain*.example.comHostname wildcard
NIS group@groupnameNIS netgroup

Critical syntax rule: There must be NO space between the client name and the options parenthesis. A space turns the rest of the line into a separate rule applying to ALL hosts.

Correct: /share client(rw) Wrong: /share client (rw) โ€” the (rw) will apply to ALL hosts!

/etc/exports options:

OptionDescriptionDefault
roRead-onlyyes
rwRead-writeno
syncWrite to disk before responding. Required for rw exports.no
asyncDon’t wait for cache flush. Speeds up ro exports, dangerous for rw.yes
root_squashroot on client maps to nobody on serveryes
no_root_squashroot on client acts as root on serverno
all_squashAll users (including root) map to nobodyno
no_all_squashRegular users map by UID/GIDyes
anonuid=NUID for anonymous user65534
anongid=NGID for anonymous group65534
subtree_checkChecks permissions in parent directoriesno
no_subtree_checkDisables subtree check. Improves reliability.yes
fsid=NFilesystem ID. In NFSv4, fsid=0 or fsid=root = pseudo-filesystem root.โ€”
# /etc/exports examples
/srv/data        192.168.1.10(rw,sync,no_root_squash)
/srv/data        192.168.1.0/24(ro,async)
/srv/public      *(ro,all_squash)
/home            client5.example.com(rw,sync,root_squash)

root_squash is enabled by default. This protects against a compromised client root. no_root_squash is needed, for example, for NFS-based backups.


Management Utilities

exportfs

Reads /etc/exports and manages exports without restarting NFS.

CommandDescription
exportfsShow current exports
exportfs -vShow with detailed options
exportfs -rRe-read /etc/exports and re-export everything
exportfs -aExport everything from /etc/exports
exportfs -u host:/pathUnexport a specific path
exportfs -uaUnexport all
exportfs -o opts IP:/pathTemporary export from command line
# Apply changes in /etc/exports
exportfs -r

# Temporary export without modifying /etc/exports
exportfs -o rw,no_root_squash 192.168.1.10:/srv/temp

# Remove temporary export
exportfs -u 192.168.1.10:/srv/temp

Export data is stored in:

  • /var/lib/nfs/etab โ€” detailed list with default options
  • /var/lib/nfs/xtab โ€” active exports
  • /proc/fs/nfs/exports โ€” kernel export table

showmount

Shows NFS server export information. Works remotely.

CommandDescription
showmount -eList current exports
showmount -e serverExports on a remote server
showmount -aClients and what they’ve mounted
showmount -dDirectories mounted by clients
showmount (no args)Names of connected hosts

showmount -e does NOT work with NFSv4 servers. Use exportfs -v instead.

rpcinfo

Queries the portmapper and checks RPC services.

# List all registered RPC services
rpcinfo -p

# Query a remote server
rpcinfo -p server

# Check NFS availability via UDP (null request)
rpcinfo -u server nfs

# Check via TCP
rpcinfo -t server nfs

portmapper listens on port 111; nfsd listens on port 2049.

nfsstat

Shows NFS client and server statistics from /proc/net/rpc/.

FlagDescription
nfsstat -sServer statistics
nfsstat -cClient statistics
nfsstat -nNFS statistics (without RPC)
nfsstat -rRPC statistics
nfsstat -snServer NFS statistics only
nfsstat -cnClient NFS statistics only

Mounting on the Client

Temporary mount:

mkdir /mnt/nfs_share
mount -t nfs -o vers=3 192.168.1.100:/srv/data /mnt/nfs_share

Permanent mount via /etc/fstab:

192.168.1.100:/srv/data  /mnt/nfs_share  nfs  ro,hard,intr,bg  0  0

Client mount options:

OptionDescription
ro / rwRead-only / read-write
hardOn server unavailability โ€” infinite retries (default)
softOn unavailability โ€” return error after timeout
intrAllow interrupting a hung mount (Ctrl+C)
nointrDisallow interruption
bgRetry mounting in background
fgAll retries in foreground (default)
tcpUse TCP (recommended)
udpUse UDP
vers=3Force NFSv3
rsize=NRead block size in bytes
wsize=NWrite block size in bytes
noatimeDon’t update atime on reads
nosuidIgnore SUID/SGID bits on mounted FS
noexecPrevent executing binaries
port=NSpecify NFS server port

Recommended combination: hard,intr,bg โ€” mount doesn’t hang permanently but keeps retrying.

Checking mounted NFS resources:

cat /proc/mounts              # all mounted filesystems
cat /var/lib/nfs/rmtab        # clients and their mounts (server-side)
showmount -a                  # clients with mount paths

NFS Security

NFSv3 uses two mechanisms: /etc/exports entries (who can mount what) and AUTH_SYS/AUTH_UNIX (client sends UID/GID โ€” easy to spoof).

Recommendations:

Use TCP instead of UDP:

mount -o tcp server:/share /mnt

Avoid wildcards in /etc/exports โ€” specify individual IPs.

Apply squashing for public exports:

/srv/public  192.168.1.0/24(ro,sync,all_squash,anonuid=65534,anongid=65534)

Check ports with firewall:

rpcinfo -p    # see all NFS ports

TCP Wrappers for NFS

TCP Wrappers control service access via /etc/hosts.allow and /etc/hosts.deny. Check order: hosts.allow first, then hosts.deny.

# Check if a daemon supports TCP Wrappers
ldd /sbin/rpcbind | grep libwrap
# libwrap.so.0 => ... means supported

ldd /sbin/rpc.nfsd | grep libwrap
# empty = rpc.nfsd doesn't directly support TCP Wrappers

Format:

daemon: client_list
# /etc/hosts.deny โ€” block everything
portmap: ALL
mountd: ALL
statd: ALL

# /etc/hosts.allow โ€” allow specific hosts
portmap: 192.168.1.10, 192.168.1.20
mountd: 192.168.1.0/255.255.255.0
statd: .example.com

# Subnet with mask
portmap: 192.168.24.16/255.255.255.248

# Whole domain
portmap: .example.com

# NIS group
portmap: @workstations

No restart needed after changing hosts.allow and hosts.deny โ€” changes take effect immediately.

Strategy: deny all in hosts.deny (portmap: ALL), then allow specific hosts in hosts.allow.


NFSv4 โ€” Brief Overview

The exam requires awareness, not deep knowledge.

Key differences from NFSv3:

  • Single fixed port 2049 (instead of multiple dynamic ports)
  • TCP by default
  • Built-in file locking (NLM not needed)
  • Kerberos for authentication and encryption
  • Pseudo-filesystem โ€” client sees exports as a single tree
  • idmapd for UID/GID mapping by name
  • portmapper (rpcbind) not required (but may be present for compatibility)
# In NFSv4 /etc/exports, use fsid=0 (or fsid=root) for the pseudo-FS root
/exports        192.168.1.0/24(rw,sync,fsid=0,no_subtree_check)
/exports/data   192.168.1.0/24(rw,sync,fsid=1,no_subtree_check)

Exam Cheat Sheet

Key Files

File/PathPurpose
/etc/exportsNFS server export configuration
/etc/exports.d/*.exportsAdditional export files
/etc/fstabPermanent NFS mounts on client
/etc/hosts.allowTCP Wrappers โ€” allowed hosts
/etc/hosts.denyTCP Wrappers โ€” denied hosts
/var/lib/nfs/etabDetailed export table with default options
/var/lib/nfs/xtabActive exports
/var/lib/nfs/rmtabCurrent clients and mounted paths
/proc/fs/nfs/exportsKernel export table
/proc/mountsAll mounted filesystems

Key Commands

exportfs -r                                    # apply /etc/exports
exportfs -v                                    # show exports with details
exportfs -o rw 192.168.1.10:/srv/data          # temporary export
exportfs -ua                                   # unexport all
showmount -e                                   # list exports (NFSv3 only)
rpcinfo -p                                     # list RPC services and ports
nfsstat -sn                                    # server NFS statistics
mount -t nfs -o vers=3,tcp server:/path /mnt   # mount NFSv3 with TCP
cat /proc/mounts                               # check mounted filesystems

Common Exam Pitfalls

PitfallRule
root_squashEnabled by default โ€” no_root_squash must be explicit
syncNOT default โ€” must be specified for rw exports
Space before ( in /etc/exportsCritical error โ€” opens access to ALL hosts
showmount -e with NFSv4Doesn’t work โ€” use exportfs -v
portmapper port111
nfsd port2049
TCP WrappersApply to rpcbind, not directly to rpc.nfsd
Filesystem type in /etc/fstabnfs, not nfs3
NFSv4 pseudo-FS rootfsid=0 or fsid=root