Skip Navigation
Site HomeSearch

On-Line Reference:
RedHat Linux Unleashed

Did this help?
... or
Donate at PayPal®...

Tux the Pengin

OK, here's a freebie: A simulation of the old text-based Star Trek game we used to play on HP 2100's using a Teletype ASR-33 as a console: StarTrek Game

Basic NFS File Sharing On Linux


  1. Disclaimer
  2. The Network
  3. Server Configuration
  4. Starting Up the Server
  5. Client Configuration
  6. Minimum Security
  7. Function of NFS Files
  8. Get Rid of OS X "._" Files
  9. Problems?


There are some prerequisites: Your kernel must have support for NFS compiled in, you must be able to successfully ping other computers on your network, and NFS software must be installed. Make a cursory check for NFS support by issuing the command:

locate rpc.nfsd

If you find a /usr/sbin/rpc.nfsd or /sbin/rpc.nfsd, then you probably have NFS support installed.

The Network

If you have not set up your network yet, see "Home Networking". For review, here is the network as we have it so far. For the purposes of this tip, the server (host) PC is known as "saragossa" and has a class C local IP address of

Figure 1, The Home Network

Home network diagram

Server Configuration:

Each of the Linux boxes on your network can be an NFS server, making some of its directories available to some or all of the others. For this tip, we speak as if there is only one server, however.

As root, create an /etc/exports file on the server which contains a line or lines defining the directories you wish to share. For example, /etc/exports will have the single (un-commented) line to share the directory /home/rik/riks_share:

# See exports(5) for a description.
# This file contains a list of all directories 
# exported to other computers.
# It is used by rpc.nfsd and rpc.mountd
# export list for all
/home/rik/riks_share    (rw)

Because there is no host name or IP address specified immediately before the "(rw)", the single specification line above gives access to all other computers on the local network.

Minimum Security

Before enabling connections, it is wise to make it tough for casual intrusion ( see the disclamer at the top). First, create or modify /etc/hosts.deny to include this line:

# See exports(5) for a description.
# This file contains a list of all hosts 
# denied access to this computer.
# It is used by rpc.nfsd and rpc.mountd
# Deny all! (see also, /etc/hosts.allow)

Now, create or modify /etc/hosts.allow to include a line containing the IP address of each local host you wish to share files with:

# See exports(5) for a description.
# This file contains a list of all hosts 
# denied access to this computer.
# It is used by rpc.nfsd and rpc.mountd
# Allow these hosts: (see also, /etc/hosts.deny)

Starting Up the Server

The processes that support NFS are mountd, nfsd, and portmap. In current distributions, these are part of the RPC package. So to get the server running we have to start them up using the rc.d script apropriate for your distribution. Here are some examples:

# exportfs -r
# /etc/rc.d/init.d/nfs restart =>RedHat
# /etc/rc.d/rc.nfsd restart    =>Slackware

The first command re-exports all file systems. The next one stops and restarts all NFS services. To confirm that NFS services are again running, issue the command:

# ps -ef

In the resulting list you should see portmap, rpc.mountd, and nfsd. If one or more of these are missing, you can not share files. Find yourself a network guru at your Linux Users Group!

Client Configuration:

On each client host (computer), if you have not already done so, add a line entry in the client's /etc/hosts file that identifies the server by IP address and name:    saragossa

Now, simply exporting the file systems does not make them immediately available to other hosts on the network. The other hosts must be set up to mount the exported directories, much as they would a floppy or cdrom; using the standard mount command, which is configured by the file /etc/fstab.

On each client host computer, create a mount point directory for the server and make an entry in /etc/fstab for the server host/directory you wish to mount. For example to mount our saragossa host I first created the mount point...

# mkdir /mnt/saragossa

...on my laptop, then I put the following file system entry line in the laptop???s "/etc/fstab" file:

saragossa:/home/rik/riks_share 	/mnt/saragossa	nfs	user,bg	0 0

(Note that the mount specification must all be on one line; using a wrapping editor like "pico" can foul this up - use vi or gedit, instead.) Refer to the man pages for fstab to understand the formatting. The ",bg" mounts as a background volume, preventing hanging if the server goes down, or is down when the client boots.

You can now exit your root session, by typing "exit". The next steps can be done as a user (If you put "user" in the fstab entry, above!) If you wish, you can confirm a connection with your host by pinging her:

$ ping saragossa>

You should see a recurring report of successful packet transmissions. Now, mount your host directory using

$ mount /mnt/saragossa

It may take a minute to get the prompt back the first time, have patience. If your prompt returns with no errors, you should be able to "cd /mnt/saragossa" and "dir" and see the contents of the servers shared directory. You should also be able to use your favorite file manager (kfm or gmc) to open, copy or otherwise manipulate files in the shared directory. Enjoy.

Function of Various NFS Files

contains information about how file systems should normally be exported. This is only read by exportfs.
contains information about what filesystems should be exported to whom at the moment.
contains a list of which filesystems actually are mounted by certain clients at the moment.
contains information about what filesystems are exported to actual client (individual, not subnet or whatever) at the moment.
contains the same information as /proc/fs/nfs/exports but is maintained by nfs-utils instead of directly by the kernel. It is only used if /proc is not mounted.

When a mount request arrives, mountd checks .../etab to see if that host is allowed access. If it is, an entry is placed in .../rmtab and the filesystem is exported thus creating an entry in /proc/fs/nfs/exports.

When you run "exportfs -io options host:/dir" then the entry in ../etab is changed, or a new one is added. If it is a subnet/wildcard/netgroup entry, then every line in ../rmtab is checked to see if it matches. When a match is found, ahost-specific entry is given to (or changed in) the kernel.

When you run "exportfs -a" it makes sure that all entries in /etc/exports are properly reflected in .../etab. Any extra entries in etab are left alone. Once the correct content of etab has been determined, rmtab is examine to create a list of specific-host entries for any new entries in etab. This host-specific entries are given to the kernel.

When you run "exportfs -r" it ignores the prior contents of .../etab and initialises etab to the contents of /etc/exportfs. Then it inspects rmtab and make an changes to /proc/fs/nfs/export that are necessary.

Get Rid of OS X "._" Files

When an OS X Mac saves files on non-HFS file systems, like a Linux NFS share, it puts the Apple-double information (type/creator and other resource tags) in a companion file of the same name but prefixed by "._" to hide it. It also puts a ".DS_store" file in the directory. These "dot" files wreak havoc when using UNIX tar or Linux tar gzip compression, causing premature file-end errors.

To purge a Linux NFS share of dot-underscore files, do this:

  1. Create a ".macpurge" executable file with these lines in your home directory:
    find . -name "._*" -exec rm -f {} ;
    find . -name ".DS_*" -exec rm -f {} ;
  2. Now, add an alias to your home dir ".bashrc" file:
    alias macpurge="~/.macpurge"
  3. When you want to quietly and quickly purge a directory and all its sub-dirs of "dot-underscore" files, just "cd" into that directory and execute the command "macpurge".


If your client hangs on boot, waiting to mount NFS volumes, make sure the client's /etc/fstab has "user,bg" in the mount specification. If that is not it, check /etc/lib/nfs/rmtab and delete any lines that you feel do not represent valid hosts on your lan. If you get any errors, like rpc timeouts or "permission denied", then something is wrong with your server setup, or the permissions are too tight on the shared directories. Review all the configuration files for typos. Ask your LUG network guru for help.

Print plain