Linux Networking, Part 7: Implementing NFS

By: William Wong
Friday, November 24, 2000 08:53:36 AM EST
URL: http://www.linuxplanet.com/linuxplanet/tutorials/2684/1/

Sharing Data Between Machines

If you have Windows PCs on your home network and have no pressing reason to use NFS (Network File System) support to share files, then read no farther. NFS is actually more robust than Samba, but it is also more complicated depending upon what features are used.

From a basic point of view, NFS and Samba are very similar. Both have a client and server application. Both allow a server to share files with clients. Both have clients and servers on almost every platform. The big difference is the Windows PCs have Samba-compatible clients and servers as part of their default network support and Windows requires third party software to support NFS. Conversely, UNIX systems usually come with and use NFS by default with Samba being used to provide file sharing with Windows PCs.

Perhaps the biggest difference between NFS and Samba is that NFS uses an explicit resource browser capability. This means that an NFS client can poll a particular server using the showmount program, as in showmount -e fileserver, to see what directories have been exported. Samba clients do this as well using NetBIOS but they can also determine what servers are available as well. The showmount program must be given the domain name or IP address of the server.

This article covers the basics of NFS configuration. There are a number of NFS HOWTOs and books on NFS that are good sources of information in addition to the online manual pages for the applications mentioned in this article. These should be used if security is an issue.

NFS works as well as Samba in providing file-sharing support in a closed network that is not connected to the Internet or one that has a good firewall in place. The Linux implementation of NFS tends to be relatively secure by default but it is possible to configure NFS servers, so there are open security holes.

The Linux 2.2 kernel has NFS support built-in. The NFS client and server applications tap this support. The NFS server has multitasking support that provides better performance, although this feature is targeted at larger networks.

NFS can be set up by editing the configuration files associated with the NFS support or running applications to mount or dismount an NFS directory. Most of the Linux setup applications, such as linuxconf found in Red Hat Linux, can also be used to configure the NFS server and client. It is possible to use both configuration approaches, but it is best to use one or the other unless you are familiar with how the setup application modifies the configuration files.

NFS Startup and Server Support

NFS client and server support is actually built into the Linux kernel. The NFS server application is named rpc.nfsd and the client is rpc.mountd. There is also a quota support application named rps.rquotad. These NFS deamons are normally started at boot time from the script /etc/rc.d/init.d/nfs. Most Linux implementations include this NFS support by default.

The NFS script only operates if the /etc/exports file exists and is not empty (zero length). The /etc/exportsNFS Server Support

Dynamic sharing of directories is done by rpc.nfsd using the exportfs program that changes the /etc/exports file. The following is an example using exportfs:

exportfs clientDomainName:/a/path/name/on/the/server
exportfs -o rw  :/a/path/name/on/the/server

The first exports the directory /a/path/name/on/the/server to a specified client. In this case the domain name is clientDomainName*.foo.com. This could also be an IP address or an IP address and subnet mask. NIS group names can also be used. The directory is exported as read-only when no options specified.

The second instance of exportfs exports the same directory but allows the world to access it. The exportfs supports a number of options. In this case, the command allows read-write access.

The exportfs program is also used to remove an export. This is done using the -u option as shown below:

exportfs -u client DomainName:/a/path/name/on/the/server

The /etc/exports file is used to define exported NFS directories when NFS is started. Each line in the file defines the directory to be exported and how the directory can be accessed. The following is a sample /etc/exports file:

/home/guest     (ro)
/pub                 *.local.dom(rw) (ro)

The first allows any user read-only access to the /home/guest directory. The second allows read-write access to computers with a domain name of local.dom and read-only access to everyone else.

NFS Client Support

The NFS client support is done using the Linux mount application. The following is a sample command line for mounting an NFS directory:

mount -t nfs -o rsize=1024,wsize=1024 client:/mnt/an/nfs/vol /mnt/nfs

This command explicitly declares the type as NFS (-t nfs). The rsize and wsize options specify buffer sizes that should be multiples of 1024. They can be omitted but larger values reserve larger buffers than may improve performance. Other options allow a directory to be specified as read-only or they can prevent applications in the directory or subdirectories from running.

Dismounting a mounted NFS directory is done using the umount application. The following would dismount the /mnt/nfs directory.

umount /mnt/nfs

Mounting a shared directory can also be done when Linux starts up. In this case, an entry, like the following, is added to the /etc/fstab file. This file is also used for other file systems as well such as Samba file systems:

# device			mountpoint	fs-type	options			dump	fsckorder
client:/mnt/an/nfs/vol	/mnt/nfs		nfs	rsize=1024,wsize=1024	0	0

The linuxconf program can be used to make modifications to the /etc/fstab file.

NFS Status

The NFS status application is named nfsstat. It provides details about an NFS server's NFS client and server connection information. Running the application without options displays all information.

Copyright Jupitermedia Corp. All Rights Reserved.