Linux exportfs Command Guide for NFS Shares
This article explains the role of the exportfs command
in managing Network File System (NFS) shares on Linux. It covers how the
command interacts with configuration files and the Linux kernel, why it
eliminates the need to restart the NFS daemon, and the essential
command-line flags administrators use to maintain, inspect, and update
shared directories.
The Primary Role of exportfs
The exportfs command acts as the administrative
interface between the user-defined NFS configuration files and the Linux
kernel's NFS server module.
When configuring NFS shares, administrators define directories,
access permissions, and authorized clients inside the
/etc/exports file and the /etc/exports.d/
directory. However, the kernel does not continuously monitor these files
for changes. The exportfs command reads these static
configuration files and translates them into an active export table
managed directly by the kernel, stored internally in
/var/lib/nfs/etab.
Eliminating Service Restarts
Before exportfs was standardized, applying new export
configurations often required restarting the entire NFS service
(nfs-kernel-server or nfs-server). Restarting
the daemon disrupts active client connections, risks data corruption,
and creates latency.
The exportfs command modifies the kernel's export table
dynamically. By using exportfs, system administrators can
add, modify, or remove shared directories on the fly without terminating
active client sessions or dropping network mounts.
Key Functions and Operations
The exportfs utility handles several critical share
management functions:
1. Synchronizing Exports
When modifications are made to /etc/exports, executing
exportfs with update flags synchronizes the kernel's memory
with the configuration file. It adds newly defined shares and applies
updated access control lists (ACLs) instantly.
2. Viewing Active Exports
Without any flags, or with status flags, exportfs
queries the active export table rather than just the configuration file.
This allows administrators to verify which directories are currently
accessible to remote clients and under what specific export parameters
(such as ro, rw, sync, or
root_squash).
3. Temporary Exporting and Unexporting
The tool allows administrators to export or unexport shares directly from the command line without editing configuration files. These manual modifications remain active until the next service restart or until the configuration is reloaded, making it ideal for temporary maintenance or quick data transfers.
Essential exportfs Flags
The behavior of exportfs is controlled via several
primary options:
-a(All): Operates on all directories listed in/etc/exportsand/etc/exports.d/.-r(Re-export): Re-reads configuration files and synchronizes the kernel table. It removes shares that were deleted from/etc/exportsand applies parameter changes.-u(Unexport): Unexports one or more specified directories.-v(Verbose): Displays a detailed list of shares and their active options when exporting or listing.-s(Display): Outputs the current export list formatted suitably for/etc/exports.
Common Usage Examples
Apply configuration changes:
exportfs -raThis reads
/etc/exports, updates the kernel table, and removes any shares that are no longer defined.Inspect all active exports with options:
exportfs -vThis prints each active export alongside its applied security and operational flags.
Temporarily unexport all shares:
exportfs -uaThis immediately suspends access to all shares without stopping the background NFS daemon.
Create a temporary share:
exportfs -o rw,sync 192.168.1.50:/srv/backupsThis grants
192.168.1.50read-write access to/srv/backupsimmediately without altering persistent configuration files.