Product SiteDocumentation Site

11.4. مخدم الملفات NFS

NFS ‏(Network File System) هو بروتوكول يسمح بالوصول البعيد لنظم الملفات عبر الشبكة. تستطيع جميع نظم يونكس العمل مع هذا البروتوكول؛ لكن إذا دخلت نظم ويندوز على الصورة فلا بدَّ من استخدام Samba بدلاً منه.
NFS is a very useful tool but, historically, it has suffered from many limitations, most of which have been addressed with version 4 of the protocol. The downside is that the latest version of NFS is harder to configure when you want to make use of basic security features such as authentication and encryption since it relies on Kerberos for those parts. And without those, the NFS protocol must be restricted to a trusted local network since data goes over the network unencrypted (a sniffer can intercept it) and access rights are granted based on the client's IP address (which can be spoofed).

11.4.1. تأمين NFS

If you don't use the Kerberos-based security features, it is vital to ensure that only the machines allowed to use NFS can connect to the various required RPC servers, because the basic protocol trusts the data received from the network. The firewall must also block IP spoofing so as to prevent an outside machine from acting as an inside one, and access to the appropriate ports must be restricted to the machines meant to access the NFS shares.
Older versions of the protocol required other RPC services which used dynamically assigned ports. Fortunately, with NFS version 4, only port 2049 (for NFS) and 111 (for the portmapper) are needed and they are thus easy to firewall.

11.4.2. مخدم NFS

مخدم NFS جزء من النواة لينكس؛ وهو مبني كوحدة في النَوَى التي تقدمها دبيان. إذا كان هناك رغبة بتشغيل مخدم NFS تلقائياً عند الإقلاع، يجب تثبيت الحزمة nfs-kernel-server؛ فهي تحوي سكربتات بدء التشغيل المناسبة.
يسرد ملف إعداد مخدم NFS، ‏/etc/exports،المجلدات التي سيوفرها على الشبكة (المجلدات المُصدّرة exported). بالنسبة لكل مشاركة NFS، تمنح صلاحيات الوصول فقط للأجهزة المذكورة بجوارها. يمكن التحكم بالوصول بدقة أكبر باستخدام بضعة خيارات. صيغة الملف بسيطة جداً:
/directory/to/share machine1(option1,option2,...) machine2(...) ...
Note that with NFSv4, all exported directories must be part of a single hierarchy and that the root directory of that hierarchy must be exported and identified with the option fsid=0 or fsid=root.
يمكن التعرف على الأجهزة باسم DNS أو بعنوان IP الخاص بها. كما يمكن تحديد مجموعات من الأجهزة باستخدام صيغة مثل *.falcot.com أو مجال من عناوين IP مثل 192.168.0.0/255.255.255.0 أو 192.168.0.0/24.
تُصدّر المجلدات في وضع القراءة فقط افتراضياً (أو باستخدام الخيار ro). يمنح الخيار rw صلاحيات القراءة والكتابة. يتصل عملاء NFS نموذجياً من منفذ مخصص للمستخدم الجذر (أي أنه أقل من 1024)؛ يمكن رفع هذا القيد باستخدام الخيار insecure (الخيار secure ضمني، لكن يمكن كتابته صراحة للتوضيح إذا اقتضت الحاجة).
By default, the server only answers an NFS query when the current disk operation is complete (sync option); this can be disabled with the async option. Asynchronous writes increase performance a bit, but they decrease reliability since there is a data loss risk in case of the server crashing between the acknowledgment of the write and the actual write on disk. Since the default value changed recently (as compared to the historical value of NFS), an explicit setting is recommended.
يعتبر المخدم جميع الطلبات التي تبدو أنها واردة من المستخدم الجذر على أنها ترد من المستخدم nobody، وذلك في سبيل عدم منح صلاحيات الجذر على نظام الملفات لأي عميل NFS. هذا السلوك يوافق الخيار root_squash، وهو مُفعّل افتراضياً. أما الخيار no_root_squash، الذي يُعطّل هذا السلوك، فهو خطر ويجب استخدامه فقط في البيئات المسيطر عليها. يسمح الخياران anonuid=uid وanongid=gid بتحديد مستخدم زائف آخر لاستخدامه بدلاً من UID/GID 65534 (التي توافق المستخدم nobody والمجموعة nogroup).
With NFSv4, you can add a sec option to indicate the security level that you want: sec=sys is the default with no special security features, sec=krb5 enables authentication only, sec=krb5i adds integrity protection, and sec=krb5p is the most complete level which includes privacy protection (with data encryption). For this to work you need a working Kerberos setup (that service is not covered by this book).
هناك خيارات أخرى متاحة؛ وهي موثّقة في صفحة الدليل exports(5)‎.

11.4.3. عميل NFS

كما في نظم الملفات الأخرى، يجب ربط (mount) مشاركات NFS في شجرة ملفات النظام لمدجها معها. بما أن نظام الملفات هذا له خصوصياته، فقد أضيفت بعض التعديلات على صيغة الأمر mount والملف /etc/fstab.

مثال 11.22. الربط اليدوي باستخدام الأمر mount

          # mount -t nfs4 -o rw,nosuid arrakis.internal.falcot.com:/shared /srv/shared

مثال 11.23. مدخلة NFS في الملف /etc/fstab

arrakis.internal.falcot.com:/shared /srv/shared nfs4 rw,nosuid 0 0
The entry described above mounts, at system startup, the /shared/ NFS directory from the arrakis server into the local /srv/shared/ directory. Read-write access is requested (hence the rw parameter). The nosuid option is a protection measure that wipes any setuid or setgid bit from programs stored on the share. If the NFS share is only meant to store documents, another recommended option is noexec, which prevents executing programs stored on the share. Note that on the server, the shared directory is below the NFSv4 root export (for example /export/shared), it is not a top-level directory.
تشرح صفحة الدليل nfs(5)‎ ‎جميع الخيارات بشيء من التفصيل.