The exportfs command is used in Linux systems to manage NFS (Network File System) file system exports. It allows administrators to view, add, and remove NFS shares without directly modifying the /etc/exports file. This command is part of the NFS server utilities and is essential for dynamically managing shared file systems.
-
Export NFS Directories:
The primary purpose ofexportfsis to export or unexport directories specified in the/etc/exportsfile, making them available to NFS clients. -
Manage Active Exports:
The command can be used to modify the list of currently exported directories without restarting the NFS server, providing real-time control over NFS exports.
Here are the most common options and examples of how to use exportfs:
This exports all the filesystems defined in the /etc/exports file. This is useful after editing the /etc/exports file.
sudo exportfs -a-a: Export or unexport all directories listed in/etc/exports.
You can display a list of all currently exported directories along with their options using:
sudo exportfs -v-v: Shows detailed information about the exported filesystems, including client access rights.
You can unexport a specific directory (remove it from being shared with clients) by using the following command:
sudo exportfs -u /path/to/directory-u: Unexports the specified directory, making it unavailable to clients.
To unexport all exported directories, use:
sudo exportfs -uaThis removes all active exports, making all shared directories inaccessible to clients.
You can also export a directory manually without editing the /etc/exports file. For example:
sudo exportfs -o rw,sync 192.168.1.0/24:/path/to/shareIn this case, the directory /path/to/share is exported to all clients in the 192.168.1.0/24 subnet with read-write (rw) and synchronous (sync) options.
-o: Specifies the export options (same options as in/etc/exports).
If you modify the /etc/exports file and want to apply the changes without restarting the NFS server, use:
sudo exportfs -r-r: Reexports all filesystems, incorporating any changes made to the/etc/exportsfile.
Suppose you want to temporarily share a directory with a specific subnet:
sudo exportfs -o rw,no_subtree_check 192.168.1.0/24:/srv/sharedThis exports /srv/shared to the 192.168.1.0/24 subnet with read-write access and without performing subtree checks.
To stop sharing the /srv/shared directory:
sudo exportfs -u /srv/sharedThis unexports the directory, making it inaccessible to clients.
After setting up your exports, you can check the current active exports using:
sudo exportfs -vThis will display a list of all active exports, along with client permissions and options.
Here’s a quick summary of some key options for the exportfs command:
-a: Export all filesystems listed in/etc/exports.-u: Unexport the specified directory.-r: Reexport all directories, useful for applying changes made in/etc/exports.-v: Show detailed information about exported filesystems.-o: Manually specify export options for a directory.
The exportfs command is an essential tool for managing NFS exports on Linux systems. It allows for the dynamic exporting and unexporting of directories without requiring a restart of the NFS server, making it a convenient utility for real-time management of file-sharing environments.