[ Current Issue Home | Issue #3 Home | FAQ ]��

The FreeBSD 'zine
Featured Articles: NFS
## A Primer
## Bill Swingle <>

Intro

Among the many different file systems that FreeBSD supports is a very unique type, the Network File System or NFS. NFS allows you to share directories and files on one machine with one or more other machines via the network they are attached to. Using NFS, users and programs can access files on remote systems as if they were local files.

NFS has several benefits:

	o Local workstations dont need as much disk space because
	  commonly used data can be stored on a single machine and
	  still remain accessible to everyone on the network.

	o There is no need for users to have unique home directories
	  on every machine on your network.  Once they have an
	  established directory that is available via NFS it can be
	  accessed from anywhere.

	o Storage devices such as floppies and CD-ROM drives can be
	  used by other machines on the network eliminating the need
	  for extra hardware.
  

How It Works

NFS is composed of two sides -- a client side and a server side. Think of it as a want/have relationship. The client *wants* the data that the server side *has*. The server shares it's data with the client. In order for this system to function properly a few processes have to be configured and running properly.

The server has to be running the following processes:

	o nfsd - The NFS Daemon which services requests from NFS clients

	o mountd - The NFS Mount Daemon which actually carries out requests 
	  that nfsd passes on to it.
  

The client side only needs to run a single process:

	o nfsiod - The NFS async I/O Daemon which services requests from
	  it's NFS server.
  

Configuration

Luckily for us, on a FreeBSD system this setup is a snap. The processes that need to be running can all be run at boot time with a few mods to your /etc/rc.conf file.

On the NFS server make sure you have:

	nfs_server_enable="YES"
	nfs_server_flags="-u -t -n 4"
	mountd_flags="-r"
  

mountd is automatically run whenever the NFS server is enabled. The '-u' and '-t' flags to nfsd tell it to serve UDP and TCP clients. The '-n 4' flag tells nfsd to start 4 copies of itself.

On the client, make sure you have:

	nfs_client_enable="YES"
	nfs_client_flags="-n 4"
  

Like nfsd, the '-n 4' tells nfsiod to start 4 copies of itself.

The last configuration step requires that you create a file called /etc/exports. The exports file specifies which file systems on your server will be shared (aka "exported") and with what clients they will be shared. Each line in the file specifies a file system to be shared. There are a handful of options that can be used in this file but I will only touch on a few of them. You can find out about the rest in the exports man page.

Here are a few example /etc/exports entries:

This line exports /cdrom to three silly machines that have the same domain name as the server (hence the lack of a domain name for each) or have entries in your /etc/hosts file. The -ro flag makes the shared file system read-only. With this flag the remote system will not be able to make any changes to the the shared file system.

	/cdrom -ro moe larry curly
  

This line exports /home to three hosts by IP address. This is a useful setup if you have a private network but don't have DNS running. The -alldirs flag allows all the directories below the specified file system to be exported as well.

	/home  -alldirs  10.0.0.2 10.0.0.3 10.0.0.4
  

This line exports /a to two machines that have different domain names than the server. The -maproot=0 flag allows the root user on the remote system to write to the shared file system as root. Without the -maproot=0 flag even if someone has root access on the remote system they won't be able to modify files on the shared file system.

	/a  -maproot=0  host.domain.com box.example.com
  

In order for a client to share an exported file system it must have permission to do so. Make sure your client is listed in your /etc/exports file.

Making it all Work

Now that you have made all these changes you can just reboot and let FreeBSD start everything for you at boot time or you can run the following commands as root:

On the NFS server:

	nfsd -u -t -n 4
	mountd -r
  

On the NFS client:

	nfsiod -n 4
  

Now you should be ready to actually mount a remote file system. This can be done one of two ways. In these examples the server's name will be "server" and the client's name will be "client". If you just want to temporarily mount a remote file system or just want to test out your config you can run a command like this as root on the client:

	mount server:/home /mnt
  

This will mount /home on the server on /mnt on the client. If everything is setup correctly you should be able to go into /mnt on the client and see all the files that are on the server.

If you want to permanently (each time you reboot) mount a remote file system you need to add it to your /etc/fstab file. Here is an example line:

	server:/home    /mnt    nfs     rw      2       2
  

Read the man page on fstab for more options.

Practical Uses

There are many very cool uses for NFS. I use it quite a bit on the LAN I admin. Here are a few ways I have found it to be useful.

I have several machines on my network but only one of them has a CD-ROM drive. Why? Because I have that one CD-ROM drive shared with all the others via NFS. The same can be done with floppy drives.

With so many machines on the network it gets old having your personal files strewn all over the place. I have a central nfs server that houses all user home directories and shares them with the rest of the machines on the LAN, so no matter where I login I have the same home directory.

When you get to reinstalling FreeBSD on one of your machines NFS is the way to go as it is faster than FTP. Just slap your distribution CD in your file server and away you go.

I have a common /usr/ports/distfiles directory that all my machines share. That way when I go to install a port that I already installed on a different machine I don't have to download the source all over again.

Other Info

Man pages: nfsd, nfsiod, mountd, showmount, exports, mount, fstab


(A bit old but should still have some useful info)

I hope that you can find even more uses for NFS on your network. If you do please write me and let me know. I would be interested to hear about it.

Bill Swingle

Return to Issue #3

Contact: <>
Last modified: $Date: 1999/06/26 05:29:52 $
Copyright � 2023, The FreeBSD 'zine
All rights reserved.