هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
The server exports folders in /etc/exports to chosen clients with options (rw, root_squash …). Clients mount them. Access is checked by UID/GID numbers on the server's files — so the same user must have the same UID on all machines (or use LDAP/IdM). NFSv4 needs only port 2049/tcp.
| Item | RHEL / Rocky / Alma | Ubuntu / Debian |
|---|---|---|
| Server packages | nfs-utils | nfs-kernel-server |
| Client packages | nfs-utils (+ autofs) | nfs-common (+ autofs) |
| Service | nfs-server.service | nfs-server.service (nfs-kernel-server) |
| Exports | /etc/exports, /etc/exports.d/*.exports | the same |
| Settings | /etc/nfs.conf | the same |
| Port | 2049/tcp (NFSv4); v3 also needs rpcbind and mountd | the same |
Install on RHEL, Rocky, Alma and Fedora
dnf -y install nfs-utils
systemctl enable --now nfs-server
firewall-cmd --permanent --add-service=nfs
firewall-cmd --reload(For NFSv3 clients also add the rpc-bind and mountd services.)
Install on Ubuntu and Debian
apt-get update
apt-get install -y nfs-kernel-server
systemctl enable --now nfs-server
ufw allow from 10.0.1.0/24 to any port nfsFirst configuration: safe exports
Make the folders and export them only to the clients that need them:
/srv/nfs/web 10.0.1.11(rw,sync,root_squash,no_subtree_check) 10.0.1.12(rw,sync,root_squash,no_subtree_check)
/srv/nfs/backup 10.0.2.0/24(rw,sync,root_squash,no_subtree_check)
/srv/nfs/iso *.corp.example.com(ro,sync,all_squash,no_subtree_check)| Option | Meaning |
|---|---|
| Client list (IP, network, host names) | Only these clients may mount. Never * for writable exports. |
rw / ro | Read-write or read-only. |
sync | Write to disk before answering (safe; async is faster but can lose data). |
root_squash (default) | Root on the client is mapped to nobody on the server — client root is not server root. |
all_squash + anonuid/anongid | Everyone is mapped to one user (good for public read-only shares). |
no_subtree_check | Recommended; avoids problems when files are renamed. |
Only NFSv4 (fewer ports, no rpcbind needed for clients):
[nfsd]
vers3=nexportfs -rav
exporting 10.0.1.11:/srv/nfs/web
exporting 10.0.2.0/24:/srv/nfs/backup
…
exportfs -v
systemctl restart nfs-serverOn RHEL with SELinux, NFS can export normal folders; for web content served by Apache/Nginx from an NFS mount, the client needs setsebool -P httpd_use_nfs 1.
Mount on the clients
dnf -y install nfs-utils
mkdir -p /var/www/shared
mount -t nfs4 files.corp.example.com:/srv/nfs/web /var/www/shared
df -h /var/www/shared
nfsstat -mPermanent in /etc/fstab (with _netdev so boot waits for the network):
files.corp.example.com:/srv/nfs/web /var/www/shared nfs4 rw,_netdev,nofail,hard,timeo=600 0 0Or autofs — mount on first use, unmount when idle (good for home folders):
/home/remote /etc/auto.home* -rw,sync files.corp.example.com:/srv/nfs/home/&Daily use: the commands and the real uses
exportfs -v
exportfs -rav
showmount -e files.corp.example.com
nfsstat -s
nfsstat -m
mount | grep nfs
ss -tn state established '( sport = :2049 )'(showmount uses NFSv3 services; with vers3=n it may not answer — that is normal.)
Real uses at work:
- Shared content for several web/app servers; shared home folders with autofs.
- Backup targets; ISO and package repositories (read-only).
- Kubernetes persistent volumes with the NFS CSI driver or a provisioner (for small clusters).
Make it safe
Security checklist:
- Export only to specific clients; never writable to
*. - Keep
root_squash; userowherever writing is not needed. - NFSv4 only; firewall 2049 to client networks only.
- Same UIDs/GIDs everywhere (central identity: FreeIPA/IdM, LDAP, AD) — or squash to one user.
- For untrusted networks use Kerberos (
sec=krb5p: authentication + encryption). - Back up the exported data; monitor free space.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
mount.nfs4: access denied by server while mounting | The client is not in the export list, or the path is wrong. | Check /etc/exports (client IP/name); exportfs -rav. |
Permission denied when writing as root | root_squash (as designed). | Write as a normal user with rights, or set group permissions. |
Files show owner nobody | UID/GID differs, or the NFSv4 ID mapping domain differs. | Same UIDs everywhere; same Domain in /etc/idmapd.conf. |
| Mount hangs at boot | No network yet, or the server is down. | _netdev,nofail in fstab; use autofs. |
Stale file handle | The export or file changed on the server. | umount -f / umount -l and mount again. |
mount.nfs: Connection timed out | Firewall blocks 2049. | Open the nfs service on the server for the client network. |
Next steps
- Quick how-tos: Share a folder with NFS, Mount shares on demand with autofs.
- Command page: exportfs, Command page: showmount, Command page: mount.
- Learn it for RHCSA: Set up an NFS server, Mount NFS through fstab, autofs. Practise: Lab: RHCSA NFS and autofs.
- Windows clients: Samba.
1What does root_squash do?
Root on the client becomes nobody on the server, so client root can not act as server root.
2Why does a mounted share show files owned by nobody?
The UID/GID or the NFSv4 ID mapping domain is different between client and server.