Massive update to the NFS chapter.

This update has been bounced around, revised, rewritten, and audited
by darn near every member of the -doc team.

Submitted by: Tom Rhodes
PR: docs/35098
This commit is contained in:
Michael Lucas 2002-03-07 21:19:11 +00:00
parent 4215ca5392
commit e4e67f3452
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/head/; revision=12384

View file

@ -376,6 +376,10 @@ host2.example.com link#1 UC 0 0
between the two subnets, is often used when we need to implement between the two subnets, is often used when we need to implement
packet filtering or firewall security in either or both packet filtering or firewall security in either or both
directions.</para> directions.</para>
<para>If you want this machine to actually forward packets
between the two interfaces, you need to tell FreeBSD to enable
this ability.
</sect2> </sect2>
<sect2 id="dedicated-router"> <sect2 id="dedicated-router">
@ -646,6 +650,13 @@ host2.example.com link#1 UC 0 0
<sect1 id="nfs"> <sect1 id="nfs">
<sect1info> <sect1info>
<authorgroup>
<author>
<firstname>Tom</firstname>
<surname>Rhodes</surname>
<contrib>Reorganized and enhanced by </contrib>
</author>
</authorgroup>
<authorgroup> <authorgroup>
<author> <author>
<firstname>Bill</firstname> <firstname>Bill</firstname>
@ -658,44 +669,41 @@ host2.example.com link#1 UC 0 0
<indexterm><primary>NFS</primary></indexterm> <indexterm><primary>NFS</primary></indexterm>
<para>Among the many different file systems that FreeBSD supports is <para>Among the many different file systems that FreeBSD supports is
the Network File System or NFS. NFS allows you the Network File System, also known as <acronym>NFS</acronym>.
to share directories and files on one machine with others <acronym>NFS</acronym> allows a system to share directories and files
via the network they are attached to. Using NFS, users and with others over a network. By using <acronym>NFS</acronym>, users and
programs can access files on remote systems as if they were local programs can access files on remote systems almost as if they were local
files.</para> files.</para>
<para>NFS has several benefits:</para> <para>Some of the most notable benefits that <acronym>NFS</acronym> can provide are:</para>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para>Local workstations do not need as much disk space because <para>Local workstations use less disk space because
commonly used data can be stored on a single machine and still commonly used data can be stored on a single machine and still
remain accessible to everyone on the network.</para> remain accessible to others over the network.</para>
</listitem> </listitem>
<listitem> <listitem>
<para>There is no need for users to have unique home directories <para>There is no need for users to have separate home directories
on every machine on your network. Once they have an established on every network machine. Home directories could be setup on the
directory that is available via NFS it can be accessed from <acronym>NFS</acronym> server and made available throughout the network.</para>
anywhere.</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Storage devices such as floppies and CDROM drives can be <para>Storage devices such as floppy disks, CDROM drives, and ZIP drives
used by other machines on the network eliminating the need for can be used by other machines on the network. This may reduce the number
extra hardware.</para> of removable media drives throughout the network.</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<sect2> <sect2>
<title>How It Works</title> <title>How <acronym>NFS</acronym> Works</title>
<para>NFS is composed of two sides &ndash; a client side and a <para><acronym>NFS</acronym> consists of at least two main parts: a server
server side. Think of it as a want/have relationship. The client and one or more clients. The client remotely accesses the data that is stored
<emphasis>wants</emphasis> the data that the server side on the server machine. In order for this to function properly a few
<emphasis>has</emphasis>. The server shares its data with the processes have to be configured and running:</para>
client. In order for this system to function properly a few
processes have to be configured and running.</para>
<para>The server has to be running the following daemons:</para> <para>The server has to be running the following daemons:</para>
<indexterm> <indexterm>
@ -723,141 +731,129 @@ host2.example.com link#1 UC 0 0
<tbody> <tbody>
<row> <row>
<entry>nfsd</entry> <entry>nfsd</entry>
<entry>The NFS Daemon which services requests from NFS <entry>The <acronym>NFS</acronym> daemon which services requests from
clients.</entry> the <acronym>NFS</acronym> clients.</entry>
</row> </row>
<row> <row>
<entry>mountd</entry> <entry>mountd</entry>
<entry>The NFS Mount Daemon which actually carries out <entry>The <acronym>NFS</acronym> mount daemon which carries out
requests that &man.nfsd.8; passes on to it.</entry> the requests that &man.nfsd.8; passes on to it.</entry>
</row> </row>
<row> <row>
<entry>portmap</entry> <entry>portmap</entry>
<entry> The <command>portmapper</command> daemon which <entry> The portmapper daemon
allows NFS clients to find out which port the NFS server allows <acronym>NFS</acronym> clients to discover which port the <acronym>NFS</acronym> server
is using.</entry> is using.</entry>
</row> </row>
</tbody> </tbody>
</tgroup> </tgroup>
</informaltable> </informaltable>
<para>The client side only needs to run a single daemon:</para> <para>The client can also run a daemon, known as
<indexterm> <application>nfsiod</application>. The <application>nfsiod</application>
<primary>NFS</primary> daemon services the requests from the <acronym>NFS</acronym> server. This
<secondary>client</secondary> is optional, and improves performance, but is not required for normal
</indexterm> and correct operation. See the &man.nfsiod.8; manual page for more information.
<indexterm> </para>
<primary><application>nfsiod</application></primary>
</indexterm>
<informaltable frame="none">
<tgroup cols="2">
<tbody>
<row>
<entry>nfsiod</entry>
<entry>The NFS async I/O Daemon which services requests
from its NFS server.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</sect2> </sect2>
<sect2 id="configuring-nfs"> <sect2 id="configuring-nfs">
<title>Configuring NFS</title> <title>Configuring <acronym>NFS</acronym></title>
<indexterm> <indexterm>
<primary>NFS</primary> <primary>NFS</primary>
<secondary>configuration</secondary> <secondary>configuration</secondary>
</indexterm> </indexterm>
<para>Luckily for us, on a FreeBSD system this setup is a snap. The <para><acronym>NFS</acronym> configuration is a relatively straightforward
processes that need to be running can all be run at boot time with process. The processes that need to be running can all start at boot time with
a few modifications to your <filename>/etc/rc.conf</filename> a few modifications to your <filename>/etc/rc.conf</filename>
file.</para> file.</para>
<para>On the NFS server make sure you have:</para> <para>On the <acronym>NFS</acronym> server, make sure that the following options
are configured in the <filename>/etc/rc.conf</filename> file:</para>
<programlisting>portmap_enable="YES" <programlisting>portmap_enable="YES"
nfs_server_enable="YES" nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4"
mountd_flags="-r"</programlisting> mountd_flags="-r"</programlisting>
<para><command>mountd</command> is automatically run whenever the <para><command>mountd</command> runs automatically whenever the
NFS server is enabled. The <option>-u</option> and <acronym>NFS</acronym> server is enabled.</para>
<option>-t</option> flags to <command>nfsd</command> tell it to
serve UDP and TCP clients. The <option>-n 4</option> flag tells
<command>nfsd</command> to start 4 copies of itself.</para>
<para>On the client, make sure you have:</para> <para>On the client, make sure this option is present in
<filename>/etc/rc.conf</filename>:</para>
<programlisting>nfs_client_enable="YES" <programlisting>nfs_client_enable="YES"</programlisting>
nfs_client_flags="-n 4"</programlisting>
<para>Like <command>nfsd</command>, the <option>-n 4</option> tells <para>
<command>nfsiod</command> to start 4 copies of itself.</para> The <filename>/etc/exports</filename>
file specifies which filesystems <acronym>NFS</acronym> should export (sometimes
<para>The last configuration step requires that you create a file referred to as <quote>share</quote>).
called <filename>/etc/exports</filename>. The exports file Each line in <filename>/etc/exports</filename> specifies a filesystem to be exported and
specifies which file systems on your server will be shared which machines have access to that filesystem. Along with what machines have access
(a.k.a., <quote>exported</quote>) and with what clients they will to that filesystem, access options may also be specified. There are many such options
be shared. Each line in the file specifies a file system to be that can be used in this file but only a few will be mentioned here. You can easily discover
shared. There are a handful of options that can be used in this other options by reading over the &man.exports.5; manual page.</para>
file but only a few will be mentioned here. You can find out
about the rest in the &man.exports.5; manual page.</para>
<para>Here are a few example <filename>/etc/exports</filename> <para>Here are a few example <filename>/etc/exports</filename>
entries:</para> entries:</para>
<indexterm> <indexterm>
<primary>NFS</primary> <primary>NFS</primary>
<secondary>exporting filesystems</secondary> <secondary>Examples of exporting filesystems</secondary>
</indexterm> </indexterm>
<para>The following line exports <filename>/cdrom</filename> to
three silly machines that have the same domain name as the server <para>The following examples give an idea of how to export filesystems,
although the settings may be different depending on
your environment and network configuration.
For instance, to export the <filename>/cdrom</filename> directory to
three example machines that have the same domain name as the server
(hence the lack of a domain name for each) or have entries in your (hence the lack of a domain name for each) or have entries in your
<filename>/etc/hosts</filename> file. The <option>-ro</option> <filename>/etc/hosts</filename> file. The <option>-ro</option>
flag makes the shared file system read-only. With this flag, the flag makes the exported file system read-only. With this flag, the
remote system will not be able to make any changes to the remote system will not be able to write any changes to the
shared file system.</para> exported file system.</para>
<programlisting>/cdrom -ro moe larry curly</programlisting> <programlisting>/cdrom -ro host1 host2 host3</programlisting>
<para>The following line exports <filename>/home</filename> to three <para>The following line exports <filename>/home</filename> to three
hosts by IP address. This is a useful setup if you have a hosts by IP address. This is a useful setup if you have a
private network but do not have DNS running. The private network without a <acronym>DNS</acronym> server configured.
<option>-alldirs</option> flag allows all the directories below Optionally the <filename>/etc/hosts</filename> file could be configured
the specified file system to be exported as well.</para> for internal hostnames; please review &man.hosts.5; for more
information. The <option>-alldirs</option> flag allows the subdirectories
to be mount points. In other words, it will not mount the subdirectories
but permit the client to mount only the directories that are required or
needed.</para>
<programlisting>/home -alldirs 10.0.0.2 10.0.0.3 10.0.0.4</programlisting> <programlisting>/home -alldirs 10.0.0.2 10.0.0.3 10.0.0.4</programlisting>
<para>The following line exports <filename>/a</filename> to two <para>The following line exports <filename>/a</filename> so that two
machines that have different domain names than the server. The clients from different domains may access the filesystem. The
<option>-maproot=0</option> flag allows <option>-maproot=root</option> flag allows the <username>root</username>
the root user on the remote system to write to the shared user on the remote system to write data on the exported filesystem as
file system as root. Without the -maproot=0 flag even if <username>root</username>. If the -maproot=root flag is not specified, then even if
someone has root access on the remote system they will not a user has <username>root</username> access on the remote system, they will not
be able to modify files on the shared file system.</para> be able to modify files on the exported filesystem.</para>
<programlisting>/a -maproot=0 host.domain.com box.example.com</programlisting> <programlisting>/a -maproot=root host.example.com box.example.org</programlisting>
<para>In order for a client to access- an exported file system it must <para>In order for a client to access an exported filesystem, the client must
have permission to do so. Make sure your client is listed in your have permission to do so. Make sure the client is listed in your
<filename>/etc/exports</filename> file.</para> <filename>/etc/exports</filename> file.</para>
<para>In <filename>/etc/exports</filename>, each line represents <para>In <filename>/etc/exports</filename>, each line represents
the export information for one filesystem to one host. A the export information for one filesystem to one host. A
remote host can only be specified once for each local remote host can only be specified once per filesystem, and may only
filesystem, and you can only have one default entry per local have one default entry. For example, assume that <filename>/usr</filename>
filesystem. For example, let's assume that is a single filesystem. The following <filename>/etc/exports</filename>
<filename>/usr</filename> is a single filesystem. The would be valid:</para>
following <filename>/etc/exports</filename> is invalid:</para>
<programlisting>/usr/src client <programlisting>/usr/src client
/usr/ports client</programlisting> /usr/ports client</programlisting>
<para>One filesystem, <filename>/usr</filename>, has two lines <para>One filesystem, <filename>/usr</filename>, has two lines
specifying its exports to the same host, specifying exports to the same host, <hostid>client</hostid>.
<hostid>client</hostid>. The correct format is:</para> The correct format for this situation is:</para>
<programlisting>/usr/src /usr/ports client</programlisting> <programlisting>/usr/src /usr/ports client</programlisting>
@ -872,42 +868,43 @@ nfs_client_flags="-n 4"</programlisting>
<programlisting># Export src and ports to client01 and client02, but only <programlisting># Export src and ports to client01 and client02, but only
# client01 has root privileges on it # client01 has root privileges on it
/usr/src /usr/ports -maproot=0 client01 /usr/src /usr/ports -maproot=root client01
/usr/src /usr/ports client02 /usr/src /usr/ports client02
# The "client" machines have root and can mount anywhere # The client machines have root and can mount anywhere
# up /exports. Anyone inhe world can mount /exports/obj read-only # on /exports. Anyone in the world can mount /exports/obj read-only
/exports -alldirs -maproot=0 client01 client02 /exports -alldirs -maproot=root client01 client02
/exports/obj -ro</programlisting> /exports/obj -ro</programlisting>
<para>You must restart <para>You must restart
<command>mountd</command> whenever you modify <command>mountd</command> whenever you modify
<filename>/etc/exports</filename> to make changes take <filename>/etc/exports</filename> so the changes can take effect.
effect. This can be accomplished by sending the hangup signal This can be accomplished by sending the hangup signal
to the <command>mountd</command> process:</para> to the <command>mountd</command> process:</para>
<screen>&prompt.root; <userinput>kill -HUP `cat /var/run/mountd.pid`</userinput></screen> <screen>&prompt.root; <userinput>kill -HUP `cat /var/run/mountd.pid`</userinput></screen>
<para>Now that you have made all these changes you can just reboot <para>Alternatively, a reboot will make FreeBSD set everything
and let FreeBSD start everything for you at boot time, or you can up properly. A reboot is not necessary though.
run the following commands as root:</para> Executing the following commands as <username>root</username>
should start everything up.</para>
<para>On the NFS server:</para> <para>On the <acronym>NFS</acronym> server:</para>
<screen>&prompt.root; <userinput>portmap</userinput> <screen>&prompt.root; <userinput>portmap</userinput>
&prompt.root; <userinput>nfsd -u -t -n 4</userinput> &prompt.root; <userinput>nfsd -u -t -n 4</userinput>
&prompt.root; <userinput>mountd -r</userinput></screen> &prompt.root; <userinput>mountd -r</userinput></screen>
<para>On the NFS client:</para> <para>On the <acronym>NFS</acronym> client:</para>
<screen>&prompt.root; <userinput>nfsiod -n 4</userinput></screen> <screen>&prompt.root; <userinput>nfsiod -n 4</userinput></screen>
<para>Now you should be ready to actually mount a remote file <para>Now everything should be ready to actually mount a remote file
system. This can be done one of two ways. In these examples the system. In these examples the
server's name will be <literal>server</literal> and the client's server's name will be <literal>server</literal> and the client's
name will be <literal>client</literal>. If you just want to name will be <literal>client</literal>. If you only want to
temporarily mount a remote file system or just want to test out temporarily mount a remote file system or would rather test the
your configuration you can run a command like this as root on the configuration, just execute a command like this as <username>root</username> on the
client:</para> client:</para>
<indexterm> <indexterm>
<primary>NFS</primary> <primary>NFS</primary>
<secondary>mounting filesystems</secondary> <secondary>mounting filesystems</secondary>
@ -916,56 +913,54 @@ nfs_client_flags="-n 4"</programlisting>
<para>This will mount the <filename>/home</filename> directory <para>This will mount the <filename>/home</filename> directory
on the server at <filename>/mnt</filename> on the client. If on the server at <filename>/mnt</filename> on the client. If
everything is setup correctly you should be able to go into everything is set up correctly you should be able to enter
/mnt on the client and see all the files that are on the <filename>/mnt</filename> on the client and see all the files
server.</para> that are on the server.</para>
<para>If you want to automatically mount a remote file system <para>If you want to automatically mount a remote filesystem
each time the computer boots, add the filesystem to each time the computer boots, add the filesystem to the
<filename>/etc/fstab</filename>. Here is an example:</para> <filename>/etc/fstab</filename> file. Here is an example:</para>
<programlisting>server:/home /mnt nfs rw 0 0</programlisting> <programlisting>server:/home /mnt nfs rw 0 0</programlisting>
<para>Read the &man.fstab.5; manual page for more options.</para> <para>The &man.fstab.5; manual page lists all the available options.</para>
</sect2> </sect2>
<sect2> <sect2>
<title>Practical Uses</title> <title>Practical Uses</title>
<para>There are many very cool uses for NFS. Some of the more common <para><acronym>NFS</acronym> has many practical uses. Some of the more common
ones are listed below.</para> ones are listed below:</para>
<indexterm> <indexterm>
<primary>NFS</primary> <primary>NFS</primary>
<secondary>uses</secondary> <secondary>uses</secondary>
</indexterm> </indexterm>
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para>Have several machines on a network and share a CDROM or <para>Set several machines to share a CDROM or
floppy drive among them. This is cheaper and often more other media among them. This is cheaper and often
convenient.</para> a more convenient method to install software on multiple machines.</para>
</listitem> </listitem>
<listitem> <listitem>
<para>With so many machines on a network, it gets old having your <para>On large networks, it might be more convenient to configure a
personal files strewn all over the place. You can have a central <acronym>NFS</acronym> server in which to store all the user
central NFS server that houses all user home directories and home directories. These home directories can then be exported to
shares them with the rest of the machines on the LAN, so no the network so that users would always have the same home directory,
matter where you log in you will have the same home regardless of which workstation they log in to.</para>
directory.</para>
</listitem> </listitem>
<listitem> <listitem>
<para>When you get to reinstalling FreeBSD on one of your <para>You can use an exported CDROM to install
machines, NFS is the way to go! Just pop your distribution software on multiple machines.</para>
CDROM into your file server and away you go!</para>
</listitem> </listitem>
<listitem> <listitem>
<para>Have a common <filename>/usr/ports/distfiles</filename> <para>Several machines could have a common
directory that all your machines share. That way, when you go <filename>/usr/ports/distfiles</filename> directory.
to install a port that you have already installed on a different That way, when you need to install a port on several machines, you can
machine, you do not have to download the source all over quickly access the source without downloading it on each machine.</para>
again!</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
</sect2> </sect2>
@ -992,14 +987,15 @@ nfs_client_flags="-n 4"</programlisting>
<indexterm><primary>amd</primary></indexterm> <indexterm><primary>amd</primary></indexterm>
<indexterm><primary>automatic mounter daemon</primary></indexterm> <indexterm><primary>automatic mounter daemon</primary></indexterm>
<para>&man.amd.8;, which is also known as the automatic mounter <para>&man.amd.8; (the automatic mounter daemon)
daemon, is a useful utility used for automatically mounting a is a useful daemon that automatically mounts a
remote filesystem whenever a file or directory within that remote filesystem whenever a file or directory within that
filesystem is accessed. Filesystems that are inactive for a filesystem is accessed. Filesystems that are inactive for a
period of time will also be automatically unmounted by period of time will also be automatically unmounted by
<application>amd</application>. Using <application>amd</application>. Using
<application>amd</application> provides a simplistic alternative <application>amd</application> provides a simple alternative
to static mounts.</para> to permanent mounts, as permanent mounts should be listed in the
<filename>/etc/fstab</filename>.</para>
<para><application>amd</application> operates by attaching <para><application>amd</application> operates by attaching
itself as an NFS server to the <filename>/host</filename> and itself as an NFS server to the <filename>/host</filename> and