-->
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:
An example of an /etc/exports file helps to show the use of these options. A pound sign on a line means a comment. Heres 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.
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.
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:
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
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:
Previous | Table of Contents | Next |