متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 79NFS server · Network

Install and set up an NFS server

NFS shares folders between Linux and Unix systems over the network: shared home folders, web content for many web servers, backups, and storage for Kubernetes (with an NFS provisioner). It is simple and fast, but its security depends on careful exports. This guide sets up an NFSv4 server on RHEL and Ubuntu, writes safe exports, mounts the share on clients (fstab and autofs), explains root squashing and user IDs, and covers the errors you will meet — also in the RHCSA exam.

  • 10 الدروس
  • 15 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

79.1

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.

ItemRHEL / Rocky / AlmaUbuntu / Debian
Server packagesnfs-utilsnfs-kernel-server
Client packagesnfs-utils (+ autofs)nfs-common (+ autofs)
Servicenfs-server.servicenfs-server.service (nfs-kernel-server)
Exports/etc/exports, /etc/exports.d/*.exportsthe same
Settings/etc/nfs.confthe same
Port2049/tcp (NFSv4); v3 also needs rpcbind and mountdthe same

79.2

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.)

79.3

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 nfs

الأوامر في هذا الدرس

79.4

First configuration: safe exports

Make the folders and export them only to the clients that need them:

mkdir -p /srv/nfs/web /srv/nfs/backup
chown root:webteam /srv/nfs/web && chmod 2775 /srv/nfs/web
/etc/exports
/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)
OptionMeaning
Client list (IP, network, host names)Only these clients may mount. Never * for writable exports.
rw / roRead-write or read-only.
syncWrite 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/anongidEveryone is mapped to one user (good for public read-only shares).
no_subtree_checkRecommended; avoids problems when files are renamed.

Only NFSv4 (fewer ports, no rpcbind needed for clients):

/etc/nfs.conf
[nfsd]
vers3=n
exportfs -rav
exporting 10.0.1.11:/srv/nfs/web
exporting 10.0.2.0/24:/srv/nfs/backup
…
exportfs -v
systemctl restart nfs-server

On 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.

79.5

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

Permanent in /etc/fstab (with _netdev so boot waits for the network):

/etc/fstab
files.corp.example.com:/srv/nfs/web  /var/www/shared  nfs4  rw,_netdev,nofail,hard,timeo=600  0 0
systemctl daemon-reload
mount -a

Or autofs — mount on first use, unmount when idle (good for home folders):

/etc/auto.master.d/home.autofs
/home/remote  /etc/auto.home
/etc/auto.home
*  -rw,sync  files.corp.example.com:/srv/nfs/home/&
dnf -y install autofs
systemctl enable --now autofs
ls /home/remote/alice

79.6

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).

79.7

Make it safe

Security checklist:

  • Export only to specific clients; never writable to *.
  • Keep root_squash; use ro wherever 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.

79.8

Update and remove

dnf -y upgrade nfs-utils
apt-get install --only-upgrade -y nfs-kernel-server
exportfs -ua
systemctl disable --now nfs-server

Unmount on all clients first (or they hang with hard mounts).

79.9

Fix common problems

ProblemCauseFix
mount.nfs4: access denied by server while mountingThe 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 rootroot_squash (as designed).Write as a normal user with rights, or set group permissions.
Files show owner nobodyUID/GID differs, or the NFSv4 ID mapping domain differs.Same UIDs everywhere; same Domain in /etc/idmapd.conf.
Mount hangs at bootNo network yet, or the server is down._netdev,nofail in fstab; use autofs.
Stale file handleThe export or file changed on the server.umount -f / umount -l and mount again.
mount.nfs: Connection timed outFirewall blocks 2049.Open the nfs service on the server for the client network.

79.10

Next steps

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.

كل الأوامر في هذا الفصل