exportfs
The exportfs command is used to maintain the NFS table of exported file systems. It is a crucial tool for managing NFS shares defined in the /etc/exports file. This guide explains the usage of exportfs, including its options and typical use cases.
Usage
exportfs [options] [client:/directory ...]Common Options
-a: Export or unexport all directories listed in/etc/exports.-r: Reexport all directories. This is useful after modifying/etc/exports.-u: Unexport one or more directories.-v: Verbose output. Useful for debugging and seeing detailed information.-o: Specify export options (overrides/etc/exports).
Examples
Export All NFS Shares
To export all directories listed in /etc/exports:
sudo exportfs -aReexport All NFS Shares
To reexport all directories (e.g., after modifying /etc/exports):
sudo exportfs -rUnexport All NFS Shares
To unexport all directories listed in /etc/exports:
sudo exportfs -uaExport a Specific Directory
To export a specific directory to a specific client:
sudo exportfs client:/directoryExample:
sudo exportfs 192.168.1.100:/srv/nfsUnexport a Specific Directory
To unexport a specific directory:
sudo exportfs -u client:/directoryExample:
sudo exportfs -u 192.168.1.100:/srv/nfsExport with Specific Options
To export a directory with specific options (overriding /etc/exports):
sudo exportfs -o rw,sync,no_subtree_check client:/directoryExample:
sudo exportfs -o rw,sync,no_subtree_check 192.168.1.100:/srv/nfsDisplay Currently Exported File Systems
To see the list of currently exported file systems:
sudo exportfs -vPractical Use Cases
Adding a New Export
Edit
/etc/exports:sudo nano /etc/exportsAdd a line for the new export:
/new/export 192.168.1.0/24(rw,sync,no_subtree_check)Reexport NFS Shares:
sudo exportfs -r
Temporarily Export a Directory
To temporarily export a directory without modifying /etc/exports:
sudo exportfs -o rw,sync,no_subtree_check 192.168.1.100:/temporary/exportUnexporting a Directory for Maintenance
Unexport the Directory:
sudo exportfs -u 192.168.1.100:/srv/nfsPerform Maintenance.
Reexport the Directory:
sudo exportfs 192.168.1.100:/srv/nfs
Security Considerations
Restrict Access: Always specify specific clients or networks to minimize unauthorized access.
Monitor Exports: Regularly check the list of exported directories to ensure only intended shares are available.
Use Secure Options: Utilize options like
root_squashto mitigate risks associated with privileged access from clients.
Conclusion
The exportfs command is a powerful tool for managing NFS shares, allowing administrators to export, unexport, and reexport directories efficiently. Proper use of this command, along with careful configuration of /etc/exports, ensures secure and reliable NFS file sharing.
Last updated