Configure NFS Server and Client on RHEL 10 (NFSv4)
Set up an NFS server and client on RHEL 10: exports, firewalld, NFSv4-only mode, SELinux booleans, fstab and autofs mounts, security and fixes.
To configure NFS on RHEL 10, install nfs-utils on the server, create a directory, list it in /etc/exports with client and options, run exportfs -rav, enable nfs-server, and open the nfs service in firewalld. On the client, install nfs-utils and mount server:/path, then make it permanent in /etc/fstab or with autofs.
This guide belongs to our RHEL 10 setup series. It covers file sharing only. Name resolution and IP addressing for your servers are in our separate guide to configuring DNS and DHCP on RHEL 10, and web serving is in setting up Apache on RHEL 10. Commands follow Red Hat's Configuring and using network file services guide for RHEL 10.
Key takeaways
- One package,
nfs-utils, provides both server and client tools. - NFSv4 needs only TCP port 2049. NFSv3 also needs rpcbind (111) and mountd, so an NFSv4-only server is simpler to firewall.
- Exports are defined in
/etc/exportsor in files under/etc/exports.d/ending in.exports. Apply changes withexportfs -rav. root_squashis on by default. Turning it off withno_root_squashgives remote root full control of the share.- Use
_netdevin fstab, or autofs for on-demand mounts. autofs is also an RHCSA exam objective.
Lab layout
| Role | Hostname | IP address | Share |
|---|---|---|---|
| NFS server | nfs1.example.lab | 192.168.10.10 | /srv/nfs/shared, /srv/nfs/home |
| NFS client | app1.example.lab | 192.168.10.21 | Mounts at /mnt/shared |
Both machines should run RHEL 10 with working repositories and static addresses. If you have not set these up, see configuring RHEL 10 repositories and configuring networking with nmcli.
NFS versions in brief
| NFSv3 | NFSv4.x | |
|---|---|---|
| Ports | 2049 plus rpcbind 111, mountd and others | 2049/TCP only |
| State | Stateless; locking via separate services | Stateful; locking built in |
| Security | Host-based (AUTH_SYS) by default | AUTH_SYS or Kerberos (krb5, krb5i, krb5p) |
showmount -e | Works | Needs mountd, so may not work on NFSv4-only servers |
RHEL 10 clients negotiate the highest version the server offers. Use NFSv4.2 unless an old client forces NFSv3.
Part 1: Configure the NFS server
Step 1: Install the package
sudo dnf install -y nfs-utils
Step 2: Create the shared directories
sudo mkdir -p /srv/nfs/shared /srv/nfs/home
sudo chown nobody:nobody /srv/nfs/shared
sudo chmod 2775 /srv/nfs/shared
Remote root is mapped to nobody by default, so ownership by nobody lets squashed root write. For team shares, a shared group with matching GIDs on server and clients is cleaner. If UIDs and GIDs differ between machines, files will show the wrong owners; central identity (IdM or LDAP) fixes that properly.
Step 3: Define the exports
Create a drop-in file so your exports are easy to manage with automation:
sudo tee /etc/exports.d/lab.exports <<'EOF'
/srv/nfs/shared 192.168.10.0/24(rw,sync,root_squash)
/srv/nfs/home 192.168.10.21(rw,sync)
EOF
Do not put a space between the client and the opening parenthesis. 192.168.10.0/24 (rw) exports to that network with default options and gives read-write access to everyone else, which is a common and dangerous typo.
Export options you will actually use
| Option | Meaning |
|---|---|
rw / ro | Read-write or read-only. ro is the default. |
sync | Reply only after data is committed to storage. Default and safer than async. |
root_squash | Map remote root to the anonymous user. Default. |
no_root_squash | Remote root acts as root on the share. Avoid except for specific cases such as diskless clients. |
all_squash | Map every remote user to the anonymous user, useful for public drop folders. |
anonuid, anongid | Set which UID and GID squashed users become. |
sec=krb5p | Require Kerberos with authentication, integrity and encryption. |
The full list is in man 5 exports.
Step 4: Start the service and apply exports
sudo systemctl enable --now nfs-server
sudo exportfs -rav
sudo exportfs -v
exportfs -rav re-reads all export files and prints what it exports. exportfs -v shows the active exports with the effective options, including defaults you did not type.
Step 5: Open the firewall
For NFSv4 clients only:
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload
If you also serve NFSv3 clients, or want showmount -e to work, add the rpcbind and mountd services:
sudo firewall-cmd --permanent --add-service={nfs,rpc-bind,mountd}
sudo firewall-cmd --reload
To restrict access to the lab subnet, use a firewalld zone with that source instead of opening the service in the public zone.
Step 6 (optional): Make the server NFSv4-only
Red Hat documents an NFSv4-only configuration for RHEL 10. Edit /etc/nfs.conf and set, in the [nfsd] section:
[nfsd]
vers3=n
Then restart the server with sudo systemctl restart nfs-server. Red Hat's guide also describes masking the rpcbind and rpc-statd units when no NFSv3 is needed; follow the procedure for your minor release, and keep only the nfs firewalld service open.
Step 7: SELinux on the server
Keep SELinux in enforcing mode. The default policy allows the NFS server to export directories, and booleans control what clients can do:
getsebool -a | grep nfs_export
sudo setsebool -P nfs_export_all_rw on
Check denials with sudo ausearch -m AVC -ts recent before changing any boolean. Our guide to SELinux in RHEL 10 explains booleans and contexts.
Part 2: Configure the NFS client
Step 1: Install and test
sudo dnf install -y nfs-utils
sudo mkdir -p /mnt/shared
sudo mount -t nfs -o vers=4.2 nfs1.example.lab:/srv/nfs/shared /mnt/shared
findmnt /mnt/shared
nfsstat -m
nfsstat -m prints the negotiated version and mount options, which is the quickest way to confirm you got NFSv4.2. Create a test file as a normal user and check it appears on the server.
Step 2: Mount at boot with /etc/fstab
nfs1.example.lab:/srv/nfs/shared /mnt/shared nfs vers=4.2,_netdev,defaults 0 0
sudo systemctl daemon-reload
sudo mount -a
findmnt /mnt/shared
_netdev tells systemd the mount needs the network. If the server might be unavailable at boot, add nofail so the client still boots, or use autofs instead.
Step 3: Mount on demand with autofs
autofs mounts a share when someone accesses the path and unmounts it after a period of inactivity. It avoids hung boots and is commonly used for home directories.
sudo dnf install -y autofs
sudo tee /etc/auto.master.d/nfs.autofs <<'EOF'
/nfs /etc/auto.nfs
EOF
sudo tee /etc/auto.nfs <<'EOF'
shared -rw,vers=4.2 nfs1.example.lab:/srv/nfs/shared
EOF
sudo systemctl enable --now autofs
ls /nfs/shared
For per-user home directories, a wildcard map entry such as * -rw nfs1.example.lab:/srv/nfs/home/& mounts each user's folder on access. On the client, enable the use_nfs_home_dirs SELinux boolean when home directories come from NFS.
Client mount options that matter
| Option | What it does | Advice |
|---|---|---|
hard (default) | Retries I/O until the server responds | Keep for data you write; applications wait instead of getting silent errors |
soft | Returns an error after retries run out | Can corrupt data for writers; use only for read-only, non-critical mounts |
vers=4.2 | Pins the protocol version | Avoids surprise fallback to an older version |
rsize, wsize | Maximum bytes per read and write request | Defaults are negotiated and usually fine on modern networks |
nconnect=N | Opens several TCP connections to the server | Can raise throughput on fast links; test before using widely |
noatime | Skips access-time updates | Reduces metadata traffic on busy read workloads |
_netdev, nofail | Boot ordering and tolerance | Use in fstab for every network mount |
See man 5 nfs for the full list and defaults on your release.
Checking the server side
sudo exportfs -v # active exports and options
sudo ss -tnp | grep 2049 # connected clients
sudo nfsstat -s # server operation counts
sudo cat /proc/fs/nfsd/versions # protocol versions the kernel server offers
The versions file shows entries such as +4.2 for enabled and -3 for disabled, which is a quick way to confirm an NFSv4-only change took effect.
Kerberos-secured NFS in outline
For shares that hold sensitive data, Kerberos replaces "trust the client's UID" with per-user authentication. The usual path on RHEL is to join the server and clients to Red Hat Identity Management (IdM), which provides Kerberos and central users. In outline:
- Join server and clients to the IdM domain with
ipa-client-install. - Create an
nfs/service principal for the server in IdM and retrieve its keytab to the server. - Export with
sec=krb5p(orkrb5iif you need integrity but not encryption). - Mount on the client with
-o sec=krb5p. Users need a Kerberos ticket (kinit) to access files.
Red Hat's network file services guide has the exact RHEL 10 procedure. Plan the identity side first; most Kerberos NFS problems turn out to be clock skew, DNS names that do not match principals, or missing keytabs.
Practice tasks
These short tasks mirror what you may be asked to do on a real system or in an exam lab:
- Export
/srv/nfs/roread-only to one subnet and confirm a client cannot write to it. - Export a drop folder with
all_squashandanonuid/anongidset to a dedicated user, then check file ownership after a client writes. - Make a client mount persistent in
/etc/fstab, reboot, and confirm it mounts. - Replace the fstab entry with an autofs indirect map under
/nfs. - Configure autofs wildcard home directories for two users.
- Switch the server to NFSv4-only and verify with
/proc/fs/nfsd/versionsandnfsstat -mon the client.
Securing NFS
- Export to specific hosts or subnets, never to
*on a routed network. - Keep
root_squash. Useall_squashfor shared drop folders. - Prefer NFSv4-only to reduce open ports and services.
- Use Kerberos for sensitive data. With
sec=krb5pand an IdM or Kerberos realm, clients authenticate per user and traffic is encrypted. AUTH_SYS trusts whatever UID the client claims. - Restrict the firewall to client subnets with a dedicated zone.
- Audit changes to
/etc/exportsand/etc/exports.d/. Our auditd on RHEL 10 guide shows how to watch configuration files.
Troubleshooting
| Symptom | Check |
|---|---|
mount.nfs: access denied by server | Client IP not in the export, a typo in the export line, or exportfs -rav not run |
No route to host or timeouts | Firewall on the server: firewall-cmd --list-services |
Permission denied when writing | Directory ownership and mode, root squashing, export is ro, or an SELinux denial |
Files owned by nobody | UID/GID mismatch or NFSv4 ID mapping domain mismatch in /etc/idmapd.conf |
showmount -e fails | Expected on NFSv4-only servers; use exportfs -v on the server instead |
| Client hangs at boot | Missing _netdev or nofail, or use autofs |
Server logs are in the journal: journalctl -u nfs-server.
Automating with Ansible
Once the manual steps work, put them in a playbook so every server is configured the same way. The ansible.posix.mount module manages fstab entries, and ansible.posix.firewalld opens services. Red Hat also ships system roles; check the RHEL 10 documentation for the current list before choosing one. Our post on Ansible playbooks used in production has patterns to start from.
FAQ
Which package do I need for NFS on RHEL 10?
Install nfs-utils on both the server and the client. Add autofs on clients that should mount shares on demand.
Which ports does NFS use?
NFSv4 uses TCP port 2049. NFSv3 also needs rpcbind on port 111 and the mountd service. In firewalld, open the nfs service, plus rpc-bind and mountd if you support NFSv3.
How do I apply changes to /etc/exports without restarting?
Run exportfs -rav. It re-reads /etc/exports and the files in /etc/exports.d and updates the active exports. Check the result with exportfs -v.
What does root_squash do?
It maps the root user on a client to the anonymous user on the server, so remote root cannot act as root on the share. It is on by default.
How do I mount an NFS share permanently?
Add an entry to /etc/fstab with the nfs type and the _netdev option, then run mount -a. Or configure autofs to mount the share when it is accessed.
Why does showmount -e not work on my server?
showmount talks to the NFSv3 mountd service. On an NFSv4-only server, or when mountd is blocked by the firewall, it fails. Use exportfs -v on the server to list exports.
Is NFS secure enough for sensitive data?
With default AUTH_SYS security, the server trusts the client's claimed UID. For sensitive data, use Kerberos with sec=krb5p, restrict exports to known hosts, and limit the firewall to client subnets.
Practise for RHCSA
NFS client mounts and autofs appear in Red Hat's RHCSA objectives. Our RHCSA training includes these labs in our Kharadi, Pune classroom and live online. See also the RHCSA exam on RHEL 10 guide.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0