There are two daemon processes that provide the NFS services on the server. These are mountd and nfsd. Mountd is responsible for checking access permissions to the exported filesystem. When a clients tries to mount a filesystem, mountd returns a pointer to the filesystem if the client has permission to mount it.
The workhorse on the server side is the nfsd daemon. It has the responsibility of handling all filesystem requests from the clients. Once a filesystem has been mounted, all access to the data on that remote filesystem is made through nfsd. Remember that you could be exporting directories and not just entire filesystems. Therefore it’s better to say that access to the mount point and below is made through nfsd.
Also key to this whole process is the portmapper, portmap. The portmapper converts TCP/IP port numbers to RPC program numbers. What this means is that when the NFS starts up, it registers its port with the local portmap process. The clients access the server by asking the portmapper on the server for the port number of nfsd and mountd. The port number is then used on all subsequent RPC calls.
In principle, mounting a remote filesystem is like mounting a local one. The general syntax is:
One of the primary differences is that since we are an NFS filesystem, we have to explicitly tell mount, by using the ‘-t nfs option. We can also include other options such as ‘-r’ for read only. Let’s assume that we have our two machines jmohr and siemau. On siemau is an NFS filesystem that we want to mount from jmohr. Assuming that the proper entries exist in the /etc/exports file on siemau, the command on jmohr might look like this:
Like other filesystems, the local mount command parses the command into tokens and ensures that entries don’t already exist in the mount table (/etc/mnttab) for either the filesystem or the directory. Realizing that this is a remote filesystem, mount gets the IP address for siemau (by whatever means are configured on the local machine) and gets the port number of mountd on siemau. The mount command then passes mountd the pathname of the requested directory (/usr/data).
Now it’s the server’s turn. To makes sure it can service the request, mountd must first check /etc/exports for the requested filesystem. In this case /usr/data. If jmohr is permitted, mountd passes back what is called a file handle, or pointer. Now the mount back on jmohr uses that file handle and the mount point (/data) as arguments the mount() system call. Finally, an entry is placed in the local mount table.
There are two primary NFS configuration files: /etc/exports and /etc/fstab. The /etc/exports file exists on the server and list those files and directories that can be accessed by remote hosts. It can also be configured to allow or deny access to specific hosts. Since each of these is a filesystem, you can manage anything mounted by NFS through /etc/fstab. This allows you to mount remote filesystems at boot or in any way you can with a “normal” filesystem. One advantage NFS has over local filesystems is that you can configure them to be mounted only when you need them. That is, if the files in the directories are not used, the connection is not made. However, if the files are needed, the connection is automatically made. This is the concept of automounting, which we will get into next.