Setting up the NFS server

Current NFS Service Status

Depending on the options chosen when installing the Linux distribution, the NFS server may already be installed and running. To check this, log onto the host PC and type:

host# /etc/init.d/portmap status
host# /etc/init.d/nfs status
host# /etc/init.d/nfslock status

Note: On more recent Linux distributions, the portmap tool has been replaced by rpcbind

Starting NFS services after each boot

Linux uses runlevels to manage which services should run concurrently. There are normally seven runlevels, numbered from 0 to 6. For example, a system shutdown corresponds to runlevel 0 (where all services should but stopped).

When a Linux system boots, it runs in the runlevel defined as the default runlevel. For most distributions, this is either 3,4 or 5

To check the runlevels at which the NFS services are automatically started or stopped, run the following commands:

host# chkconfig  --list  portmap
host# chkconfig  --list  nfs
host# chkconfig  --list  nfslock

Each of these three commands prints a line similar to the following:

portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off

If the services are listed as off for run levels 3, 4 and 5, then change them to on with the commands:

host# chkconfig  portmap on
host# chkconfig  nfs on
host# chkconfig  nfslock on

It is not necessary to reboot the system. Instead these services can be started with the following commands:

host# /etc/init.d/portmap start
host# /etc/init.d/nfs start
host# /etc/init.d/nfslock start

The /etc/exports file

When these services are running, the NFS server must be told which directories to make available to other machines. The shared directories are refered as exported directories and are defined in the file /etc/exports. For example, we can export the directory containing the ST40 root file system with the following line in /etc/exports:

/opt/STM/STLinux-X.X/devkit/sh4/target *(rw,no_root_squash,async)

The format of the /etc/exports file is:

DIRECTORY HOST1(OPTION1,OPTION2,...) HOST2(OPTION1,OPTION2,...)

Note: There are no spaces between the host names and comma separated list of options. See man exports for more details.

If the root file system has been copied elsewhere, replace the name of the root directory with the root of the copied directory tree.

Controlling exported directories

Use the exportfs utility to list and control the NFS exported directories:

host% /usr/sbin/exportfs
/opt/STM/STLinux-2.3/devkit/sh4/target <world>
/export/u-boot  <world>
/mnt/cdrom      <world>
/tftpboot       <world>

When a new directory has been added to /etc/exports, it is exported by instructing exportfs to export all the directories in /etc/exports, as follows:

host# exportfs -a

Firewalls

The last thing to check is whether a firewall is running. Recent versions of many Linux distributions install a firewall by default; in general this is a good thing, as it helps to keep the host PC secure if it is connected directly to the Internet. NFS is considered insecure and the default rules will prevent remote clients to access your NFS services. When connected to a LAN, the firewall rules can be altered to allow more services to be accessed.

Here, rather than customizing the firewall rules we will disable the firewall altogether.

Linux firewalls rules are managed by the iptables tool. The following command checks the runlevels at which the firewall rules are applied:

host# chkconfig  --list  iptables

If the output lists this service as being on in runlevels 3,4 or 5, it can be disabled for these runlevels with the following command:

host# chkconfig iptables off

Also, it is possible to stop this service altogether with the command:

host# /etc/init.d/iptables stop