BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


Configuring and Using NFS
Pages: 1, 2

Now, login as root at alpha.



/stand/sysinstall

And select "Configure," then "Networking"; use your spacebar to select the NFS client and press OK, then exit out of /stand/sysinstall.

Before we try mounting gamma's /usr directory at alpha, let's create a mountpoint on alpha:

mkdir /share

Now issue the mount command:

mount gamma:/usr /share

If you issued this as root, you should receive your command prompt back without any error messages. To see if it mounted:

df

which should return a line that reads something like this:

gamma:/usr	5996471	  1069259   4447495	  19%	   /share

and if you issue these commands:

cd /share
ls

you should be able to see the contents of gamma's /usr directory.

When you are finished, you can unmount /share like any other mounted file system:

umount /share

Congratulations, you've just created your first NFS server; now let's fine-tune it a bit.

Normally, you won't want to export your entire /usr directory structure. Even if permissions are set correctly, you don't want remote users poking about your home and bin directories. Instead, create a subdirectory of /usr to contain the information you want remote users to access. As a practical example, I copy the packages collection into a directory I've created called /usr/packages. I then export /usr/packages and /usr/ports, so my /etc/exports looks like this:

/usr/ports	10.0.0.1
/usr/packages   10.0.0.1

The new mount command at alpha is:

mount gamma:/usr/packages /share
cd /share
ls

The above command will only show the packages collection stored on gamma. An added side benefit to the client is that they don't have to copy a package onto their hard drive in order to install it. The pkg_add command works quite nicely from the mountpoint.

NFS's behaviour is a little weird if you want to share your CD-ROM over the network. If I edit /etc/exports on gamma to add the following line:

/cdrom	-alldirs	10.0.0.1

I would expect alpha to be able to access the contents of a data CD-ROM located on gamma. If I put a data CD-ROM in gamma's CD-ROM drive, and at alpha type:

mount gamma:/cdrom /share

I get:

nfs: can't access /cdrom: Permission denied

Hmmmm... Let's try a shutdown now at gamma; perhaps nfsd needs to re-read /etc/exports. No, that made things worse, as the boot messages now include:

Starting final network daemons: mountdJun 3 15:25:48 gamma 
mountd[1537]: could not remount /cdrom: Invalid argument
Jun 3 15:25:48 gamma mountd[1537]: bad exports list line /cdrom -alldirs
10.0.0.1

If I wait long enough, I'll also start to get periodic error messages at Alt-F1. So what happened? Let's take a look at /etc/fstab:

pico /etc/fstab
# Device		Mountpoint	FStype	Options		Dump	Pass#
/dev/acd0c		/cdrom		cd9660	ro,noauto	0	0

And there's one problem: I tried to export a filesystem that is not set to mount automatically when I reboot. I can't export a filesystem that isn't mounted locally. To complicate matters further, I can't export a directory I've created, unless I create it as a subdirectory of /usr. This is where NFS gets a bit weird. Try this at gamma:

mkdir /usr/cdrom
pico /etc/exports

and modify the line to read:

/usr/cdrom	-alldirs	10.0.0.1

Save the change and issue a shutdown now. This time there shouldn't be any error messages. Now try

df

and you'll see something like this:

Filesystem  1K-blocks     Used    Avail Capacity  Mounted on
/dev/ad0s1a     49583    33637    11980    74%    /
/dev/ad0s1f   5996471  1069263  4447491    19%    /usr
/dev/acd0c     470754   470754        0   100%    /usr/cdrom
/dev/ad0s1e     19815     5671    12559    31%    /var
procfs              4        4        0   100%    /proc
mfs:1919        68647        1    63155     0%    /tmp

Note that /usr/cdrom was mounted for you; if you try

mount /cdrom
you'll see something like
cd9660: Device busy 

However,

cd /usr/cdrom
ls

should show the contents of the CD-ROM. Now, at alpha,

mount gamma:/usr/cdrom /share
cd /share
ls

should also show the contents of gamma's CD-ROM.

cd /
umount /share

You will have to be extra careful if you decide to export CD-ROMs; you don't want to inadvertently eject a mounted CD-ROM or reboot without a CD-ROM in your CD-ROM drive. I usually leave the cdrom reference commented out in /etc/exports like so:

#/usr/cdrom	-alldirs	10.0.0.1

and uncomment it out when I actually want to share my CD-ROM. I then need to issue a shutdown now so the nfsd can mount the CD-ROM. If I try to mount it myself:

mount /usr/cdrom

I get:

mount: /usr/cdrom: unknown special file or file system

However, once nfsd has mounted it, I can unmount it normally:

umount /usr/cdrom

This should get you started with NFS; read the man page for nfsd to learn how to give read-only access, group access, and user access.

Whenever you edit /etc/exports, always test your changes at the client. Mount the newly exported data to ensure that you haven't given the client access to more data then you intended.

One final note on NFS: portmap can be a security risk on computers attached to insecure networks such as the Internet. Usually, in a networked environment, there is only one computer with the Internet connection as it controls Internet access for the rest of the network. Don't run the nfsd on that computer.

Next week, we'll start familiarizing ourselves with the shells that come with your FreeBSD system.

Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.


Read more FreeBSD Basics columns.

Discuss this article in the Operating Systems Forum.

Return to the BSD DevCenter.

 





Sponsored by: