Mastering NFS: Protocol Basics, Service Setup, and Version Comparison on Linux
This guide explains the NFS (Network File System) protocol, its reliance on RPC, the ports it uses, how to activate the required daemons, differences among NFSv2/v3/v4/v4.1, and provides step‑by‑step instructions for installing, configuring, and mounting NFS on CentOS 7, including firewall and export settings.
NFS Protocol Overview
NFS (Network File System) enables file sharing across Unix‑like systems by allowing a client to access files on a remote server as if they were local disks. The NFS service listens on TCP and UDP port 2049 and relies on the RPC (Remote Procedure Call) protocol to negotiate which dynamic ports each NFS function will use.
1.1 How NFS Works
When an NFS server starts, it randomly selects unused ports below 1024 for each exported function and registers them with the RPC portmapper (program 100000). The client first contacts the RPC portmapper on port 111 to discover the correct port for the desired NFS service, then communicates directly with that daemon.
1.2 Activating NFS Services
The typical startup chain on a Linux host is:
nfs‑client → portmapper → mountd → nfs‑server (nfsd)Key daemons: rpc.nfsd: manages client authentication and permission IDs. rpc.mountd: registers exported file systems with the portmapper and provides access tokens via portmapper (default port 1111 in the example).
Before starting NFS, the RPC service must be running; otherwise NFS cannot register its ports. If RPC restarts, all NFS‑related daemons need to be restarted to re‑register.
1.3 NFS Version Comparison
Since its introduction in 1985, NFS has evolved through three major versions:
NFSv2 : First RFC‑based version, basic functionality, only synchronous writes.
NFSv3 : Adds asynchronous writes, the ACCESS request for permission checks, and various bug fixes.
NFSv4 (including 4.0 and 4.1): Introduces stateful operation, built‑in file locking, security via RPCSEC‑GSS, and a simplified request model using COMPOUND operations.
NFSv4.1 : Supports parallel storage with separate metadata (MDS) and data (DS) servers, improving scalability.
NFS Service on CentOS 7
CentOS 7 defaults to NFSv4 over TCP on port 2049. The required packages ( nfs-utils and rpcbind) are usually pre‑installed.
# System environment
OS: CentOS 7.0
NFS Server IP: 192.168.10.10
Firewall: disabled
SELINUX=disabledInstallation command: # yum install nfs-utils To make the service firewall‑friendly, edit /etc/sysconfig/nfs and set fixed ports, e.g.:
RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004Start and enable the services:
# systemctl restart rpcbind
# systemctl enable rpcbind
# systemctl start nfs-server
# systemctl enable nfs-serverConfiguration Files
The export list is defined in /etc/exports using the syntax: /path/to/share client_ip(options) Example: /nfsfile 192.168.10.*(rw,sync,root_squash) After editing, apply changes without restarting the daemon:
# export -ar # re‑export all filesystemsPractical Demonstration
Step 1 – Prepare the machines : Create a server and a client (both RHEL 7), disable iptables and SELinux, and ensure network connectivity.
Step 2 – Create the shared directory on the server :
# mkdir /nfsfile
# chmod -R 777 /nfsfile
# echo "welcome to localhost.com" > /nfsfile/readmeStep 3 – Edit /etc/exports to export the directory to the client subnet. /nfsfile 192.168.10.*(rw,sync,root_squash) Step 4 – Start and enable NFS and RPC services (see commands above).
Step 5 – Mount the export on the client :
# mount -t nfs 192.168.10.10:/nfsfile /nfsfile
# cat /nfsfile/readme # should display the welcome messageTo make the mount persistent, add an entry to /etc/fstab:
192.168.10.10:/nfsfile /nfsfile nfs defaults 0 0Useful commands: showmount -e SERVER_IP – list exported directories. exportfs -ar – re‑export after changes.
With these steps, you have a fully functional NFS share that can be accessed by multiple clients, and you understand the underlying protocol, daemon interactions, and version‑specific features.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
