Red Hat Enterprise Linux 4: System Administration Guide
Prev                                                                    Next
Chapter 14. 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 
Enterprise 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. 
  14.1. 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. 
Prev                               Home                                 Next
Additional Resources                 Up                  Mounting NFS File 
                                                                  Systems
  Red Hat Enterprise Linux 4: System 
           Administration Guide
     Chapter 14. Network File System 
Prev              (NFS)               Next
14.2. 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
           Warning
           The mount point directory on the local machine (/misc/local in the 
 
           above example) must exist before this command can be executed.
    In this command, shadowman.example.com is the hostname of the NFS file 
    server, /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. 
    14.2.1. 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 before this 
    command can be executed. 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 is mounted from the server. 
    14.2.2. Mounting NFS File Systems using autofs
    A third option for mounting an NFS share is the use of the autofs service. 
    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
    Next, 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. 
           Note
           The directory /misc must exist on the local file system. There should 
 
           be no subdirectories in /misc on the local file system. 
To start the autofs service, at a shell prompt, type the following command: 
/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, you must tell the automount daemon(s) to reload by typing the 
following command at a shell prompt: 
/sbin/service autofs reload
To learn how to configure autofs to start at boot time, and for information on 
managing services, refer to Chapter 12 
                                         Controlling Access to Services
                                                                          . 
14.2.3. Using TCP
The default transport protocol for NFSv4 is TCP; however, the Red Hat 
Enterprise Linux 4 kernel includes support for NFS over UDP. To use NFS 
over UDP, include the -o udp option to mount when mounting the NFS
exported file system on the client system. 
There are three ways to configure an NFS file system export. On demand 
via the command line (client side), automatically via the /etc/fstab file 
(client side), and automatically via autofs configuration files, such as 
/etc/auto.master and /etc/auto.misc (server side with NIS). 
For example, on demand via the command line (client side): 
mount -o udp shadowman.example.com:/misc/export
/misc/local
When the NFS mount is specified in /etc/fstab (client side): 
server:/usr/local/pub    /pub    nfs
rsize=8192,wsize=8192,timeo=14,intr,udp
When the NFS mount is specified in an autofs configuration file for a NIS 
server, available for NIS enabled workstations: 
myproject -rw,soft,intr,rsize=8192,wsize=8192,udp
penguin.example.net:/proj52
Since the default is TCP, if the -o udp option is not specified, the NFS
exported file system is accessed via TCP. 
The advantages of using TCP include the following: 
   •   Improved connection durability, thus less NFS stale file handles
       messages.
   •   Performance gain on heavily loaded networks because TCP 
       acknowledges every packet, unlike UDP which only acknowledges 
       completion.
   •   TCP has better congestion control than UDP (which has none). On a 
       very congested network, UDP packets are the first packets that are 
       dropped. This means that if NFS is writing data (in 8K chunks) all of 
       that 8K must be retransmitted over UDP. Because of TCP's reliability, 
       only parts of that 8K data are transmitted at a time.
   •   Error detection. When a TCP connection breaks (due to the server 
       being unavailable) the client stops sending data and restarts the 
       connection process once the server becomes available. With UDP, 
       since it's connectionless, the client continues to pound the network 
       with data until the server reestablishes a connection.
The main disadvantage is that there is a very small performance hit due to 
the overhead associated with the TCP protocol. 
14.2.4. Preserving ACLs
The Red Hat Enterprise Linux 4 kernel provides ACL support for the ext3 
file system and ext3 file systems mounted with the NFS or Samba 
protocols. Thus, if an ext3 file system has ACLs enabled for it and is NFS 
exported, and if the NFS client can read ACLs, they are used by the NFS 
client as well. 
Prev                              Home                             Next
Network File System                Up                Exporting NFS File 
(NFS)                                                          Systems
  Red Hat Enterprise Linux 4: System 
          Administration Guide
     Chapter 14. Network File System 
Prev              (NFS)               Next
14.3. Exporting NFS File Systems
Sharing or serving 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, you must be running the X 
Window System, have root privileges, and have the system-config-nfs
RPM package installed. To start the application, select the Main Menu 
Button (on the Panel) => System Settings => Server Settings => NFS, or 
type the command system-config-nfs. 
Figure 141. NFS Server Configuration Tool
To add an NFS share, click the Add button. The dialog box shown in Figure 
142 appears. 
The Basic tab requires the following information: 
   •   Directory — Specify the directory to share, such as /tmp.
   •   Host(s) — Specify the host(s) with which to share the directory. 
       Refer to Section 14.3.2 
                               Hostname Formats
                                                for an explanation of 
       possible formats.
   •   Basic permissions — Specify whether the directory should have 
       readonly or read/write permissions.
Figure 142. Add Share
The General Options tab allows the following options to be configured: 
   •   Allow connections from port 1024 and higher — Services started 
       on port numbers less than 1024 must be started as root. Select this 
       option to allow the NFS service to be started by a user other than 
       root. This option corresponds to insecure.
   •   Allow insecure file locking — Do not require a lock request. This 
       option corresponds to insecure_locks.
   •   Disable subtree checking — If a subdirectory of a file system is 
       exported, but the entire file system is not exported, the server checks 
       to see if the requested file is in the subdirectory exported. This check 
       is called subtree checking. Select this option to disable subtree 
       checking. If the entire file system is exported, selecting to disable 
       subtree checking can increase the transfer rate. This option 
       corresponds to no_subtree_check.
   •   Sync write operations on request — Enabled by default, this 
       option does not allow the server to reply to requests before the 
       changes made by the request are written to the disk. This option 
       corresponds to sync. If this is not selected, the async option is used.
          o   Force sync of write operations immediately — Do not 
              delay writing to disk. This option corresponds to no_wdelay.
The User Access tab allows the following options to be configured: 
   •   Treat remote root user as local root — By default, the user and 
       group IDs of the root user are both 0. Root squashing maps the user 
       ID 0 and the group ID 0 to the user and group IDs of anonymous so 
       that root on the client does not have root privileges on the NFS 
       server. If this option is selected, root is not mapped to anonymous, 
       and root on a client has root privileges to exported directories. 
       Selecting this option can greatly decrease the security of the system. 
       Do not select it unless it is absolutely necessary. This option 
       corresponds to no_root_squash.
   •   Treat all client users as anonymous users — If this option is 
       selected, all user and group IDs are mapped to the anonymous user. 
       This option corresponds to all_squash .
          o   Specify local user ID for anonymous users — If Treat all 
              client users as anonymous users is selected, this option 
              lets you specify a user ID for the anonymous user. This option 
              corresponds to anonuid.
          o   Specify local group ID for anonymous users — If Treat all 
              client users as anonymous users is selected, this option 
              lets you specify a group ID for the anonymous user. This 
              option corresponds to anongid.
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). 
14.3.1. 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 readonly permissions, but, 
/misc/export     speedy.example.com(rw,sync)
would allow users from speedy.example.com to mount /misc/export with 
read/write privileges. 
Refer to Section 14.3.2 
                        Hostname Formats
                                         for an explanation of possible 
hostname formats. 
Refer to the Red Hat Enterprise Linux Reference Guide for a list of 
options that can be specified. 
           Caution
           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 readwrite access and 
           denies all other users. The second line grants users from 
           speedy.example.com readonly access (the default) and allows the rest of 
           the world readwrite access. 
    Each time you change /etc/exports, you must inform the NFS daemon of 
    the change, or reload the configuration file with the following command: 
/sbin/service nfs reload
    14.3.2. Hostname Formats
    The host(s) can be in the following forms: 
       •   Single machine — A fully qualified domain name (that can be 
           resolved by the server), hostname (that can be resolved by the 
           server), or an IP address.
       •   Series of machines specified with wildcards — Use the * or ? 
           character to specify a string match. Wildcards are not to be used 
           with IP addresses; however, they may accidentally work if reverse 
           DNS lookups fail. When specifying wildcards in fully qualified domain 
           names, dots (.) are not included in the wildcard. For example, 
           *.example.com includes one.example.com but does not include 
           one.two.example.com.
   •   IP networks — Use a.b.c.d/z, where a.b.c.d is the network and z
       is the number of bits in the netmask (for example 192.168.0.0/24). 
       Another acceptable format is a.b.c.d/netmask, where a.b.c.d is the 
       network and netmask is the netmask (for example, 
       192.168.100.8/255.255.255.0).
   •   Netgroups — In the format @group-name, where group-name is the 
       NIS netgroup name.
14.3.3. 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. Refer to Chapter 12 
Controlling Access to Services for details. 
Prev                              Home                                 Next
Mounting NFS File                   Up               Additional Resources
Systems