NFS

 

NFS


 

Exporting NFS File Systems

Sharing files from an NFS server is known as exporting the directories. The NFS Server Configuration Tool can be used to configure a system as an NFS server.

To use the NFS Server Configuration Tool, be running the X Window System, have root privileges, and have the redhat-config-nfs RPM package installed. To start the application...

Main Menu | System Settings | Server Settings | NFS Server
...or type the command...

redhat-config-nfs

NFS Server Configuration Tool

To add an NFS share, click the Add button.

The Basic tab requires the following information:

Add Share

The General Options tab allows the following options to be configured:

The User Access tab allows the following options to be configured:

To edit an existing NFS share, select the share from the list, and click the Properties button. To delete an existing NFS share, select the share from the list, and click the Delete button.

After clicking OK to add, edit, or delete an NFS share from the list, the changes take place immediately — the server daemon is restarted, and the old configuration file is saved as /etc/exports.bak. The new configuration is written to /etc/exports.

The NFS Server Configuration Tool reads and writes directly to the /etc/exports configuration file. Thus, the file can be modified manually after using the tool, and the tool can be used after modifying the file manually (provided the file was modified with correct syntax).

 

Command Line Configuration

If you prefer editing configuration files using a text editor or if you do not have the X Window System installed, you can modify the configuration file directly.

The /etc/exports file controls what directories the NFS server exports. Its format is as follows:

 directory 
 hostname(
 options)

The only option that needs to be specified is one of sync or async ( sync is recommended). If sync is specified, the server does not reply to requests before the changes made by the request are written to the disk.

For example:

 /misc/export     speedy.example.com(sync)

would allow users from speedy.example.com to mount /misc/export with the default read-only permissions, but:

 /misc/export     speedy.example.com(rw,sync)

would allow users from speedy.example.com to mount /misc/export with read/write privileges.

Be careful with spaces in the /etc/exports file. If there are no spaces between the hostname and the options in parentheses, the options apply only to the hostname. If there is a space between the hostname and the options, the options apply to the rest of the world. For example, examine the following lines:

 /misc/export speedy.example.com(rw,sync)
/misc/export speedy.example.com (rw,sync)

The first line grants users from speedy.example.com read-write access and denies all other users. The second line grants users from speedy.example.com read-only access (the default) and allows the rest of the world read-write access.

Each time you change /etc/exports, inform the NFS daemon of the change, or reload the configuration file with the following command:

 /sbin/service nfs reload

 

Hostname Formats

The host(s) can be in the following forms:

 

Starting and Stopping the Server

On the server that is exporting NFS file systems, the nfs service must be running.

View the status of the NFS daemon with the following command:

 /sbin/service nfs status

Start the NFS daemon with the following command:

 /sbin/service nfs start

Stop the NFS daemon with the following command:

 /sbin/service nfs stop

To start the nfs service at boot time, use the command:

 /sbin/chkconfig --level 345 nfs on

You can also use chkconfig, ntsysv or the Services Configuration Tool to configure which services start at boot time.

 

Mounting NFS File Systems

Use the mount command to mount a shared NFS directory from another machine:

 mount shadowman.example.com:/misc/export /misc/local

The mount point directory on local machine ( /misc/local in the above example) must exist.

In this command, shadowman.example.com is the hostname of the NFS fileserver, /misc/export is the directory that shadowman is exporting, and /misc/local is the location to mount the file system on the local machine. After the mount command runs (and if the client has proper permissions from the shadowman.example.com NFS server) the client user can execute the command ls /misc/local to display a listing of the files in /misc/export on shadowman.example.com.

 

Mounting NFS File Systems using /etc/fstab

An alternate way to mount an NFS share from another machine is to add a line to the /etc/fstab file. The line must state the hostname of the NFS server, the directory on the server being exported, and the directory on the local machine where the NFS share is to be mounted. You must be root to modify the /etc/fstab file.

The general syntax for the line in /etc/fstab is as follows:

 
server:/usr/local/pub    /pub   nfs    rsize=8192,wsize=8192,timeo=14,intr

The mount point /pub must exist on the client machine. After adding this line to /etc/fstab on the client system, type the command mount /pub at a shell prompt, and the mount point /pub will be mounted from the server.

 

Mounting NFS File Systems using autofs

A third option for mounting an NFS share is the use of autofs. Autofs uses the automount daemon to manage your mount points by only mounting them dynamically when they are accessed.

Autofs consults the master map configuration file /etc/auto.master to determine which mount points are defined. It then starts an automount process with the appropriate parameters for each mount point. Each line in the master map defines a mount point and a separate map file that defines the file systems to be mounted under this mount point. For example, the /etc/auto.misc file might define mount points in the /misc directory; this relationship would be defined in the /etc/auto.master file.

Each entry in auto.master has three fields. The first field is the mount point. The second field is the location of the map file, and the third field is optional. The third field can contain information such as a timeout value.

For example, to mount the directory /proj52 on the remote machine penguin.example.net at the mount point /misc/myproject on your machine, add the following line to auto.master:

 
/misc   /etc/auto.misc --timeout 60

Add the following line to /etc/auto.misc:

 
myproject  -rw,soft,intr,rsize=8192,wsize=8192 penguin.example.net:/proj52

The first field in /etc/auto.misc is the name of the /misc subdirectory. This directory is created dynamically by automount. It should not actually exist on the client machine. The second field contains mount options such as rw for read and write access. The third field is the location of the NFS export including the hostname and directory.

The directory /misc must exist on the local file system. There should be no subdirectories in /misc on the local file system.

Autofs is a service. To start the service, at a shell prompt, type the following commands:

 /sbin/service autofs restart

To view the active mount points, type the following command at a shell prompt:

 /sbin/service autofs status

If you modify the /etc/auto.master configuration file while autofs is running, tell the automount daemon(s) to reload by typing the following command at a shell prompt:

 /sbin/service autofs reload

 

Network File System (NFS)

Network File System (NFS) is a way to share files between machines on a network as if the files were located on the client's local hard drive. Red Hat Linux can be both an NFS server and an NFS client, which means that it can export file systems to other systems and mount file systems exported from other machines.

 

Why Use NFS?

NFS is useful for sharing directories of files between multiple users on the same network. For example, a group of users working on the same project can have access to the files for that project using a shared directory of the NFS file system (commonly known as an NFS share) mounted in the directory /myproject. To access the shared files, the user goes into the /myproject directory on his machine. There are no passwords to enter or special commands to remember. Users work as if the directory is on their local machines.


 

Home