5.4. Configuring an NFS server

The NFS protocol is designed to be portable across different machines, operating systems, network architectures, and transport protocols. This portability is achieved through the use of Remote Procedure Call (RPC) primitives built on top of an eXternal Data Representation (XDR) (RFC1094 NFS v2).

NFS (Network File System) version 4 is a distributed file system protocol which owes heritage to NFS protocol versions 2 [RFC1094] and 3 [RFC1813]. Unlike earlier versions, the NFS version 4 protocol supports traditional file access while integrating support for file locking and the mount protocol.

[...]

The NFS version 4 protocol [...] retains the essential characteristics of previous versions: design for easy recovery, independent of transport protocols, operating systems and filesystems, simplicity, and good performance (RFC3010)

The NFS server runs the following daemons:

These services are started with the nfs sevice:

/etc/init.d/nfs start/stop/status/restart/reload

In addition rpc.statd is used to notify the client when the NFS service is unexpectedly interrupted, and rpc.lockd allows clients to lock files accessed on the server.

These services are started with the nfslock service:

/etc/init.d/nfslock start/stop/status/restart

Programs using remote procedure calls (RPC) use specific program numbers listed in /etc/rpc. When a RPC service is started it will tell portmap which port number it is using as well as its program number.

[Note]Note

It is necessary for portmap to be running before starting any NFS service.

RPC clients connect to the portmap service, although it is possible to work around portmap if the RPC program number is known.

5.4.1. The /etc/exports file

Syntax:

directory <host>(<option1,option2,...>) <host>(<option1,...>)

Table 5.1. /etc/exports common options

OptionDescription
roRead only. There is also the read-write option rw
no_root_squashoverride the default (root_squash) where root is mapped to user nobody
asyncthe server writes to disk at predefined intervals (may cause data loss)
syncuse sync rather than async when exporting a directory read-write

5.4.2. User Mappings

Once a remote directory is mounted on the local client one would expect local users to access their files as if the directory was locally mounted. However this will only be the case if UIDs on both the local and remote systems correspond.

NFS is generally used in an environment where UIDs are common between the server and the clients.

5.4.3. Anonuid and Anongid

It is possible, using anonuid and anongid options to assign a unique anonymous UID or GID per exported directory. Users mounting that share will be given the rights of that anonymous ID on the server. For example, everybody accessing the share below will inherit the right of the remote user with UID=150 and GID=100

/share       *(rw,anonuid=150,anongid=100)

5.4.4. Root Squashing

By default the root user on the client system will be mapped to the user nobody on the server. This option is disabled in /etc/exports with the no_root_squash option.

Finally, it is possible to map all users from any client to the user nobody with the all_squash option.

5.4.5. TCPwrappers

The portmap tool has been compiled with libwrap giving us the option to control access through /etc/hosts.allow and /etc/hosts.deny.

strings `which portmap ` |grep hosts.allow

5.4.6. Using exportfs and nfsstat

The exportfs command with no arguments will show all exported directories.

Table 5.2. exportfs options

-rre-read /etc/exports and export all directories listed
-uunexport all shares (until exportfs -r is called)
-aapplies to all exports
-ospecify directories not listed in /etc/exports

The nfsstat displays statistics about NFS server and client activity. The information is read from two files:

/proc/net/rpc/nfscontains information about NFS client activity
/proc/net/rpc/nfsdcontains information about the NFS server

Table 5.3. nfsstat options

-sshow only server statistics
-cshow only client statistics
-nprint NFS statistics only
-rprint RPC statistics only
-oprint statistics for specific utility (nfs, rpc, net, fh, rc)