-->
Previous Table of Contents Next


Chapter 43
NFS

by Tim Parker

In This Chapter
•   Configuring Linux for NFS

The Network File System (NFS) was created by Sun Microsystems to share files and directories among UNIX operating systems. With NFS, when a file or directory is shared, it appears to be part of your system instead of on some remote machine. For example, if you had a Linux machine in your basement that had a filesystem full of games, NFS would let you set that games filesystem so that it appeared on your own machine as part of the standard directory structure. Every time you access the games area, you’re going over the network to the other machine, but that’s all transparent to you (except for time delays), thanks to NFS.

NFS can be used with different types of networks, but it was really designed to work with TCP/IP. NFS is still most often used over TCP/IP networks. Because of its popularity, implementations of NFS have been created on other operating systems so that directories can be shared across heterogeneous networks.

Under UNIX and Linux, NFS operates in peer-to-peer mode. This really means that your computer can act as a client of NFS services on another machine as well as a server to other machines on the network, or both simultaneously.

Many people love using the Network File System service at their business, but are scared to configure it themselves at home on their Linux system. They reason that the process must be convoluted, complex, and require a lot of knowledge about the operating systems. For this reason, many people don’t bother with NFS, which is a shame because it is one of the most useful services TCP/IP has to offer. As you will see in this chapter, it is not difficult to implement an NFS network, either. All it takes is a little time. Of course, you should have more than one machine on your network to take advantage of the service, too.


NOTE:  
Some newer products such as VisionFS make setting up and using network-mounted drives much easier. Ports of these products are available for Linux, although they are commercial.

Configuring Linux for NFS

The NFS service makes extensive use of the Remote Procedure Call service. For this reason, the RPC server daemon must be running for NFS to be implemented. On some Linux systems you can check whether RPC is active by issuing this command at the shell prompt:


rpcinfo -p

When you do, you should see a list of all the RPC servers currently running on your machine, such as these:


[root@linux tparker]# rpcinfo -p

   program vers proto  port

    100000    2   tcp   111  portmapper

    100000    2   udp   111  portmapper

    300019    1   udp   737

    100001   13   udp   791  rstatd

    100001    3   udp   791  rstatd

    100001    2   udp   791  rstatd

    100001    1   udp   791  rstatd

    100001   13   tcp   796  rstatd

    100001    3   tcp   796  rstatd

    100001    2   tcp   796  rstatd

    100001    1   tcp   796  rstatd

If RPC is running properly, you will see at least four rpcbind listings (two for UDP and two for TCP) and an entry for pcnfsd, the NFS daemon. In the example above, there is no pcnfsd entry, so we know the NFS daemon is not active yet.

You must have loaded the NFS routines when Linux was installed to be able to run NFS on your system (Linux often prompts you whether you want NFS active when you run the installation script). If you didn’t load it during your initial program load, add it when you need it through whatever Disk Set installation routine is supplied with your version of Linux. Some systems, such as Caldera’s OpenLinux and many Slackware releases, load NFS automatically when the system boots, whether you use it or not.

Configuring Linux Servers

With most versions of Linux, NFS is started and stopped by a script called /etc/nfs. This can be linked into the startup routines to automatically load NFS when the system boots by linking the /etc/nfs file to the file /etc/rc2.d/Sname. To shut down NFS properly, you need to also link /etc/nfs to the file /etc/rc0.d/Kname. If you want to manually start and stop the NFS daemon, you can do this with the following commands:


/etc/nfs start



/etc/nfs stop


NOTE:  
Some versions of Linux use different files and directories for NFS scripts and configuration information. If the files mentioned in this chapter don’t seem to exist, try using /etc/rc.d/init.d/nfs or /etc/init.d/nfs for the startup script file.

The /etc/nfs command starts up and shuts down the NFS server daemon when the appropriate command is issued. When you issue the start command, the daemons that are activated are echoed to the screen:


$ /etc/nfs start

Starting NFS services: exportfs mountd nfsd pcnfsd biod(x4)

Starting NLM services: statd lockd

With a stop command, you see a message that the daemons and server are shut down:


$ /etc/nfs stop

NFS shutdown: [NFS Shutdown Complete]

For a filesystem on a Linux machine to be available to NFS clients on other systems, the filesystem must be listed in the file /etc/exports. With some versions of Linux, the NFS daemons starts automatically if the /etc/exports file exists during boot time. This invokes a program called exportfs, which sets the filesystem as available for NFS use. If any changes are made to the /etc/exports file while the system is running, you can issue another exportfs command or simply reboot the machine to make the changes effective.


Previous Table of Contents Next