-->
Previous Table of Contents Next


The format of the /etc/exports file follows:


directory [ -option, option … ]

directory is the pathname of the directory or file to be shared (exported, in NFS terminology) by NFS, and options can be chosen from the following:

  ro Export the directory as read-only. (The default value is to export as read-write.)
  rw=hostnames Export the directory as read-mostly, which means read-only to most machines but read-write to specifically identified machines.
  anon=uid If an NFS request comes from an unknown user, use uid as the effective user ID for ownership and permissions.
  root=hostnames Give root access to the root users from a specified machine.
  access=client Give mount access to each client listed. A client can be a host name or a net group.

An example of an /etc/exports file helps to show the use of these options. A pound sign on a line means a comment. Here’s a sample /etc/exports file:


/usr/stuff -ro         # export as read-only to anyone

/usr  -access=clients  # export to the group called clients

/usr/public            # export as read-write to anyone

If you make changes to the /etc/exports file, shut down the NFS server daemons and start them up again. Issue an exportfs command and the system should display the names of all exported filesystems. NFS is now ready for use on your server.


WARNING:  
You may notice that some versions of Linux create a new file called /etc/xtab, which contains the filesystem information. Do not edit this file! You should not modify the contents, or the NFS server will not function properly. The /etc/xtab file is generated by the exportfs command.

Configuring Other Linux Servers

Some versions of Linux use the share command to set up a directory for export. (Many versions of Linux do not support the share command because the functions are duplicated in the /etc/exports file.) The syntax of the share command follows:


share -F nfs -o options -d description path

Where the -F option indicates that the directory or files given in path are to be set as NFS filesystems. The options following -o set the type of access in the same way as the /etc/exports file shown above. The -d option can be followed by a descriptive statement used by clients to describe the export filesystem. For example, to share the direc-tory /usr/public as read-write (the default), you could issue the following command:


share -F nfs -d “Server public directory” /usr/public

You can combine options, as shown in this example:


share -F nfs -o ro=artemis,anon=200 -d “Book material” /usr/tparker/book

This command shares the directory /usr/tparker/book, which is tagged with the description “Book material”, with everyone as read-write except for a machine called artemis, for which it is read-only. Any anonymous users accessing the system use UID 200.

The share command by itself usually shows you a list of all filesystems that are exported.

Setting Up a Linux Client

Linux can mount an NFS-exported filesystem from another machine with the mount command. The syntax for mounting an NFS filesystem follows:


mount -F nfs -o options machine:filesystem mount-point

The -F option tells the mount command the filesystem is an NFS filesystem, machine:filesystem is the name of the remote machine and the filesystem to be mounted, and mount-point is the location in the current filesystem that the remote filesystem is to be mounted. Some versions of Linux change the syntax a little. For example, some versions use a lowercase f and uppercase NFS to indicate the type. Check the man pages for exact syntax on your version.

In use, mount is easy to work with. For example, the following command mounts the filesystem /usr/public on the remote machine called artemis on the local machine in the directory called /usr/artemis:


mount -F nfs artemis:usr/public /usr/artemis

The mount point (in this case /usr/artemis) must exist for the mount to succeed.

The -o optional component of the mount command can be used to set options from the following list:

  rw Sets the mount read-write (the default value).
  ro Sets the mount read-only.
  timeo=x Gives a timeout value in tenths of a second to attempt the mount before giving up.
  retry=x Retries x times before giving up.
  soft Forces the client to give up the mount attempt if an acknowledgment is not received from the remote.
  hard The client continues trying to mount the filesystem until successful.
  intr Allows the keyboard to interrupt the mount request; otherwise, the attempts go on indefinitely.

Any of these options can be combined in one mount command, as they could be for the share command. For example, the following command line tries to mount the /usr/public directory on artemis as read-only, but gives up if the mount attempt is not acknowledged by artemis:


mount -F nfs -o soft,ro artemis:usr/public /usr/artemis

The mount command by itself usually shows all mounted filesystems.

There is a simpler way to mount commonly used directories. Put the names of the directories and their mount points in the /etc/fstab or /etc/vfstab file (the file to use depends on the version of Linux). Then you can mount the files by simply issuing the mount point name. For example, this command mounts the proper filesystem as /skunk:


mount /skunk

Summary

As you have seen in this chapter, NFS is not very complex to set up, either as a client or server. With a few minutes work you can start sharing your directories and accessing directories on other machines. NFS is a very fast and easy way to access applications and copy files on remote machines. Although the configuration is dependent on the operating system version, a quick check of help screens or man pages will show you the proper format of the commands used in this chapter.

From here you can find related information:

NIS and YP, which let you manage passwords network-wide, are discussed in Chapter 44, “NIS and YP.”
Automating processes on your system using the cron utility, very handy for system administrators, is discussed in Chapter 46, “cron and at.”
Setting up an Internet server is discussed in Chapter 47, “Setting up an Internet Site.”


Previous Table of Contents Next