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 -a

Reexport All NFS Shares

To reexport all directories (e.g., after modifying /etc/exports):

Unexport All NFS Shares

To unexport all directories listed in /etc/exports:

Export a Specific Directory

To export a specific directory to a specific client:

Example:

Unexport a Specific Directory

To unexport a specific directory:

Example:

Export with Specific Options

To export a directory with specific options (overriding /etc/exports):

Example:

Display Currently Exported File Systems

To see the list of currently exported file systems:

Practical Use Cases

Adding a New Export

  1. Edit /etc/exports:

    Add a line for the new export:

  2. Reexport NFS Shares:

Temporarily Export a Directory

To temporarily export a directory without modifying /etc/exports:

Unexporting a Directory for Maintenance

  1. Unexport the Directory:

  2. Perform Maintenance.

  3. Reexport the Directory:

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_squash to 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