Editing the /etc/exports File
The following steps describe how to configure shared directories using the
/etc/exports file.
Configure the directories that an NFS server exports, including which clients can access
those directories and what permissions they have, by editing the
/etc/exports file.
Note:
You can also configure exports in files that you create under the
/etc/exports.d directory. For example,
/etc/exports.d/myexports.
- Install
nfs-utils.If it's not already installed, install the
nfs-utilspackage.sudo dnf install nfs-utils - Configure the
/etc/exportsfile.Edit the
/etc/exportsfile to define the directories that the server makes available for clients to mount, for example:/var/folder 192.0.2.102(rw,async) /usr/local/apps *(all_squash,anonuid=501,anongid=501,ro) /var/projects/proj1 192.168.1.0/24(ro) mgmtpc(rw)Each entry includes the local path to the exported directory, followed by a list of clients that can mount the directory and then client-specific export options (in parentheses). There can't be any spaces between the client specifier and the parenthesized list of options that apply to that client.
The following information explains the example export file entries in greater detail:
-
Only the client system with the IP address
192.0.2.102can mount the/var/folderdirectory with read and write permissions. All writes to the disk are asynchronous. This means that the server doesn't wait for write requests to be written to disk before responding to further requests from the client. -
As indicated by the wildcard (*), all clients can mount the
/usr/local/appsdirectory as read-only. All connecting users, includingrootusers, are mapped to the local, unprivileged user with UID 501 and GID 501. -
All clients on the
192.168.1.0/24subnet can mount the/var/projects/proj1directory as read-only. However, the client system namedmgmtpccan mount the directory with read/write permissions.
For more information on the format of the
etc/exportsfile, see theexports(5)manual page. -
- Configure the
/etc/idmapd.conffile for NFSv4 clients.If the server serves NFSv4 clients, edit the
/etc/idmapd.conffile's definition for the Domain parameter by specifying the server's domain name.Domain = mydom.comThis setting prevents the owner and group from being incorrectly listed as the anonymous user or group (
nobodyornogroup) on NFS clients when theall_squashmount option isn't specified. - Configure the firewall to enable access only for NFSv4 clients.
To enable access through the firewall for NFSv4 clients only, use the following commands:
sudo firewall-cmd --permanent --zone=zone --add-service=nfsThis configuration assumes that
rpc.nfsdlistens for client requests on the default TCP port 2049. - Configure the firewall to enable access for NFSv3 and NFSv4 clients.
To enable access through the firewall for NFSv3 and NFSv4 clients, do the following:
-
Edit the
/etc/nfs.conffile to specify the port settings for handling network mount requests (mountdsection) and status monitoring (statdsection). Also, set the TCP port on which the network lock manager listens in thelockdsection. For example:# Ports that various services should listen on. [mountd] port = 892 [statd] port = 662 [lockd] port = 32803If any of these ports are already in use, NFS fails to start. Use the
lsof -icommand to find an unused port and then change the setting in the/etc/nfs.conffile as appropriate.To confirm on which ports RPC services are listening, use the
rpcinfo -pcommand. -
Restart the firewall service and configure the firewall to let NFSv3 connections through:
sudo firewall-cmd --permanent --zone=zone --add-port=2049/tcp --add-port=111/tcp --add-port=32803/tcp --add-port=892/tcp --add-port=662/tcp -
Reboot the server.
sudo systemctl reboot
-
- Start the
nfs-serverservice.Start the
nfs-serverservice and configure the service to start automatically when the system boots:sudo systemctl enable --now nfs-server - Verify which versions of NFS the server works with.
Run the following command to check that the server provides the NFS versions that you have configured:
sudo cat /proc/fs/nfsd/versionsFor example, the following output shows that the server provides NFSv3, NFSv4, NFSv4.1, and NFSv4.2:
+3 +4 +4.1 +4.2 - List the exported directories.
Display a list of the exported directories.
sudo showmount -eExport list for host01.mydom.com /var/folder 192.0.2.102 /usr/local/apps * /var/projects/proj1 192.168.1.0/24 mgmtpcThe exportfs command on the server displays the same information as the
showmount -ecommand.sudo /usr/sbin/exportfs -vThe showmount -a command displays all the current clients and all the exported directories that the clients have mounted.
Note:
To enable use of the showmount command from NFSv4 clients, specify a port number to the
MOUNTD_PORTparameter in/etc/nfs.conf. Then, create a firewall rule to enable access to this TCP port.