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:

Common Usage Examples