A complete step-by-step masterclass on configuring an enterprise NFS kernel server, mastering /etc/exports access parameters, and mounting remote filesystems persistently via /etc/fstab.
The Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984. It allows client computers on a network to mount remote directory shares exported by a central server and interact with files over the network as if they resided on the client's local physical disk drives.
In enterprise Linux deployments, cloud clusters, and Kubernetes architectures, NFS serves as the standard shared storage backbone for web server farms (Nginx/Apache sharing uploaded media), centralized user home directories, database backup dumps, and persistent volume claims (PVCs).
NFS operates via the client-server model over the standard TCP/IP transport layer:
open(), read(), write()).| Feature | Legacy NFSv3 | Modern NFSv4 |
|---|---|---|
| Connection State | Stateless (Server holds no client lock records). | Stateful (Tracks open file states and client leases). |
| Network Ports | Multiple dynamic ports (Requires rpcbind, mountd, statd). Difficult for firewalls. |
Single well-known TCP port 2049. Highly firewall friendly. |
| Security & Auth | Relies purely on client IP and standard numeric UIDs/GIDs (spoofable). | Native RPCSEC_GSS Kerberos authentication, ACLs, and string-based usernames. |
| Namespace Export | Exports isolated directory paths independently. | Unified pseudo-filesystem hierarchy anchored at a root export. |
# On Ubuntu / Debian systems:
sudo apt update
sudo apt install nfs-kernel-server -y
# On RHEL / Rocky Linux / AlmaLinux / Fedora:
sudo dnf install nfs-utils -y
# Create directory to share
sudo mkdir -p /srv/nfs/shared_data
# Set ownership and permissions (give full read/write access to test client)
sudo chown nobody:nogroup /srv/nfs/shared_data # Ubuntu/Debian
# sudo chown nfsnobody:nfsnobody /srv/nfs/shared_data # RHEL/CentOS
sudo chmod 777 /srv/nfs/shared_data
The /etc/exports file controls which directories are shared and with whom. Open the file in an editor:
sudo nano /etc/exports
Add the following export rule:
# Format: <Directory> <Authorized-Host/Subnet>(<Options>)
/srv/nfs/shared_data 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)
rw: Grants Read-Write access (use ro for read-only).sync: Forces the NFS server to commit write operations to physical disk storage before acknowledging the client request. Guarantees data integrity during server power loss. (The faster alternative async acknowledges immediately before disk flushing, risking data corruption).no_subtree_check: Prevents the server from verifying if a file requested by the client still resides in the exported subdirectory tree. Significantly improves performance and prevents errors when files are renamed by active processes.root_squash (Default): Maps client requests executed by root (UID 0) to unprivileged user nobody, preventing client roots from compromising server system files.no_root_squash: Allows client root users to create and edit files as true root on the server share (mandatory for diskless booting and root backup systems).# Apply /etc/exports changes without restarting daemon
sudo exportfs -ra
# Verify active exported directories
sudo exportfs -v
# Enable and start NFS server service
sudo systemctl enable --now nfs-kernel-server # Ubuntu/Debian
# sudo systemctl enable --now nfs-server # RHEL/Rocky
# Ubuntu UFW: Allow traffic from local private subnet
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw status
# RHEL Firewalld: Allow nfs, mountd, and rpcbind services
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=mountd
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo firewall-cmd --reload
# On Ubuntu / Debian client:
sudo apt update && sudo apt install nfs-common -y
# On RHEL / Rocky Linux client:
sudo dnf install nfs-utils -y
# Query available shares on the NFS server (e.g. 192.168.1.100)
showmount -e 192.168.1.100
# Expected output:
# Export list for 192.168.1.100:
# /srv/nfs/shared_data 192.168.1.0/24
# Create local mount directory on client
sudo mkdir -p /mnt/nfs_share
# Mount the remote NFS share
sudo mount -t nfs 192.168.1.100:/srv/nfs/shared_data /mnt/nfs_share
# Verify the mount is active and check disk space
df -hT /mnt/nfs_share
Manual mounts using mount vanish when the client machine reboots. To make mounts persistent, append an entry to /etc/fstab on the client:
sudo nano /etc/fstab
Add the following configuration line at the bottom:
192.168.1.100:/srv/nfs/shared_data /mnt/nfs_share nfs defaults,_netdev,nofail,timeo=14,intr 0 0
_netdev: Critical! Informs systemd to delay mounting until the physical network stack and IP addresses are completely up. Without this, system boot hangs indefinitely trying to reach an unavailable IP.nofail: Prevents boot failure if the NFS server is powered down or unreachable during client boot.timeo=14: Sets RPC timeout to 1.4 seconds before attempting retransmission.intr: Allows users to cancel or kill hung file operations if the server crashes.# Test fstab configuration without rebooting
sudo mount -a
# 1. On Client: Create a test file inside the NFS mount
echo "Hello from Client machine" > /mnt/nfs_share/client_test.txt
# 2. On Server: Check if the file instantly appeared on disk
cat /srv/nfs/shared_data/client_test.txt
# Output: Hello from Client machine
# 3. On Client: Safely unmount when testing is finished
sudo umount /mnt/nfs_share
exportfs -ra command re-reads /etc/exports and re-exports all listed directories. The -r flag re-exports all directories, and -a specifies that all entries in the exports configuration should be synchronized into the kernel's live export table without terminating existing client connections.
sync, the NFS server writes incoming data to the physical disk (or non-volatile journal) before sending an acknowledgment back to the client. Under async, the server replies as soon as data enters RAM buffers. If the server loses power or kernel panics while holding data in RAM, uncommitted client data is permanently lost and files become corrupted.
umount calls freeze waiting for the server. You can unmount forcefully using: sudo umount -f -l /mnt/nfs_share. The -f forces the unmount and -l (lazy unmount) detaches the filesystem immediately from the VFS tree while cleaning up remaining socket references in the background.
mount \\nfs-server-ip\srv\nfs\share Z:. However, for native Windows-to-Linux file sharing with file locking and Active Directory integration, Samba (SMB/CIFS) is the industry standard.
idmapd (ID mapping daemon).
ss -tan | grep :2049, or inspect the kernel's active NFS client list by running: cat /proc/fs/nfs/exports or nfsstat -s for comprehensive server I/O statistics.