- Unix Commands Reference
- Unix Commands - Home
exportfs Command in Linux
exportfs is a Linux command that helps you manage the export of directories to NFS (Network File System) clients. This command maintains the current table of the exported files systems and allows administrators to add or remove exports without restarting the NFS service.
The exportfs command is pretty useful in case you want to configure which directories are accessible to remote systems via NFS.
Table of Contents
Here is a comprehensive guide to the options available with the exportfs command −
- How to Install exportfs Command in Linux
- Syntax for exportfs Command in Linux
- Different Options Available for exportfs Command
- Examples of exportfs Command in Linux
How to Install exportfs Command in Linux
The exportfs command is part of the nfs-kernel-server package, which is not installed by default on your Linux system. However, installing this package is pretty simple and can be done from your default system’s package manager.
For example, on Debian-based systems like Ubuntu, Kali Linux, the nfs-kernel-server package can be installed using the following command −
sudo apt install nfs-kernel-server
On Red Hat-based systems like CentOS, or Fedora, you can use the below-given command to install the nfs-kernel-server package −
sudo yum install nfs-kernel-server
Or
sudo dnf install nfs-kernel-server
The Arch Linux users can run the following command to install the nfs-kernel-server package on their systems −
sudo pacman -S nfs-utils
While, on SUSE Linux, you can install the nfs-kernel-server package using zypper through the following command −
sudo zypper install nfs-kernel-server
Syntax for exportfs Command in Linux
The basic syntax to use the exportfs command in Linux is simple, which is as follows −
exportfs [option] [client:/path]
Where −
- [option] specifies the behavior of the exportfs command.
- [client:/path] indicates the client and the directory path to be exported.
Different Options Available for exportfs Command
You can customize the behavior of the exportfs command using various options, which are detailed in the table below −
Option | Description |
---|---|
-a | Export or unexport all directories listed in /etc/exports. |
-d kind, --debug kind | Turn on the debugging mode. Valid kinds are: auth, all, general, call and parse. |
-f | Clear all entries from the kernel’s export table. |
-i | Ignore the /etc/exports file and rely solely on the command line options provided. |
-o | Specify a list of export options, similar to those found in the /etc/exports file. |
-r | Reexport all directories, and synchronize the export table with /etc/exports. |
-s | Show the current export list. |
-u | Unexport one or more directories. |
-v | Be verbose, showing detailed information about the export process. |
Examples of exportfs Command in Linux
Let’s explore a few common examples of the exportfs command in a Linux system −
Exporting All Directories
To export all directories listed in the /etc/exports file, you can simply use the exportfs command with the a option:
sudo exportfs -a
The above command will read the /etc/exports file and export all the directories specified within it.
Note: You may remove sudo in case you are accessing the terminal as a root user.
Unexporting All Directories
You can also unexport all directories anytime by using the exportfs option with -au flag, as given below −
sudo exportfs -au
Once you run the command, it will remove all the current exports, and make the directories inaccessible to NFS clients.
Exporting a Specific Directory
You can also export a specific directory to a particular client using −
sudo exportfs client:/path/to/directory
You must replace the client with the client’s hostname or IP address and /path/to/directory with the directory you want to export.
Reexporting Directories
If you want to re export all directories and synchronize the export table with /etc/exports, simply use the following command −
sudo exportfs -r
Doing this will ensure that the export table is up-to-date with the current configuration in /etc/exports.
Displaying Exported Directories
To display all currently exported directories, you can execute the below-given command −
exportfs -v
The above command will show a detailed list of all exported directories and their options.
Conclusion
The exportfs command is a powerful utility used for managing NFS exports on a Linux system. It helps administrators in controlling which directories are accessible to remote clients, thus ensuring an efficient and secure file sharing process.
In this tutorial, we have covered the installation of exportfs command, along with its syntax and different options. Also, examples are provided to help users effectively manage their NFS servers and their exports.