NFS Export to Multiple Hosts
this blog assumes you already have a working NFS server, if not, use the following:
http://blog.zwiegnet.com/linux-server/setup-nfs-server-on-centos-6/
In this example we have two CentOS servers that we want to configure /etc/exports to allow export to only two hosts, rather than just one IP, or the whole network.
Prerequisites
- A running NFS server (the
nfsservice on CentOS 6,nfs-serveron CentOS 7 and AlmaLinux/Rocky/RHEL 8 to 10). - The directory to share, here
/home/ClusterStorage. - The IP addresses (or resolvable hostnames) of the clients that should be allowed in.
- Root access on the server.
Step 1: edit /etc/exports
let’s edit our handy /etc/exports file
vi /etc/exports

here’s a look at what we would need
/home/ClusterStorage 192.168.1.10(rw,sync,no_root_squash) 192.168.1.11(rw,sync,no_root_squash)

one host right after each other.
Each line is the exported directory followed by any number of client(options) pairs separated by spaces. The client IPs above are examples; use your own. Every client gets its own option list, so one host could have rw and another ro.
Watch the spacing: there must be no space between a client and its opening bracket. 192.168.1.10 (rw) exports read-only to 192.168.1.10 and read-write to everyone, because the options are then treated as a separate client with no address.
What the options do:
rwallows reads and writes (the default isro).syncmakes the server commit writes to disk before replying. It is safer and the default.no_root_squashlets root on the client act as root on the share. By default root is mapped to an unprivileged user (root_squash). Only use it for trusted hosts that need it, such as cluster nodes or backup servers.
Step 2: apply the configuration
from there run a exportfs -a to set the config
exportfs -a

exportfs -a exports everything in /etc/exports. When you change an existing file, exportfs -ra is better: it re-reads the file and also removes entries you deleted. Neither restarts the NFS service or disconnects clients.
Step 3: verify
now all we have to do is verify it’s exported
exportfs

perfect, our two IP’s are able to get to the share

exportfs -v shows the same list with the options in effect for each client. From a client you can also run showmount -e servername (for NFSv3; it may not answer on NFSv4-only servers) and then mount the share to test, as in Mount NFS Share on CentOS 6.
that’s it!
Other ways to list clients
- A whole subnet:
192.168.1.0/24(rw,sync) - Hostnames or wildcards:
node1.example.com(rw)or*.example.com(ro) - NIS netgroups:
@clusternodes(rw)
Listing individual IPs, as in this guide, is the tightest option when only a couple of machines need access.
Troubleshooting
- exportfs: Failed to resolve: a hostname in the file does not resolve. Use the IP or fix DNS/
/etc/hosts. - access denied by server while mounting: the client’s address does not match any entry (check which IP it really uses, e.g. behind NAT), or
exportfs -rawas not run after editing. - Files owned by nobody: an NFSv4 ID mapping issue, not an export problem. Make sure the idmapd domain matches on server and client.
- Mount hangs: usually the firewall. See Troubleshoot Stuck and Hung NFS Mounts.
On AlmaLinux, Rocky and RHEL 8, 9 and 10
The /etc/exports syntax and exportfs commands are unchanged. You can also put entries in separate files ending in .exports under /etc/exports.d/. Start the server and open the firewall with:
systemctl enable --now nfs-server
firewall-cmd --permanent --add-service=nfs --add-service=mountd --add-service=rpc-bind
firewall-cmd --reload
Hosted Linux servers at www.zwiegnet.com/go
