Setting up the NFS server

This page contains instructions for setting up and configuring an NFS server.

From Fedora 14 onwards, three versions of NFS are available: NFSv2, NFSv3 and NFSv4. Fedora 16 and later supports NFSv4 by default, whereas earlier versions supported NFSv3 by default. The method for starting NFS on the server is different depending upon which release of Fedora is to be used.

Current NFS Service Status

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

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

Note: rpcbind exists in Fedora 14 and later (and many other recent Linux distributions). Earlier releases use the portmap tool instead.

Starting NFS services after each boot

Linux uses the concept of runlevels to manage which services can run concurrently. There are normally seven runlevels, numbered 0 to 6. For example, a system shutdown corresponds to runlevel 0, where all services should be 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  rpcbind
host# chkconfig --list  nfs
host# chkconfig --list  nfslock

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

rpcbind 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 following commands:

host# chkconfig rpcbind on
host# chkconfig nfs on
host# chkconfig nfslock on

Note: In Fedora 16 and later, chkconfig has been replaced by systemctl.

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

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

Current NFS Service Status

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

host# service rpcbind status
host# service nfs status
host# service nfslock status

Starting NFS services after each boot

Use the following commands to start the required services:

host# systemctl start rpcbind.service
host# systemctl start nfs-server.service
host# systemctl start nfs-lock.service
host# systemctl start nfs-idmap.service

Use the following commands to make sure that these services re-start at boot time:

host# systemctl enable rpcbind.service
host# systemctl enable nfs-server.service
host# systemctl enable nfs-lock.service
host# systemctl enable nfs-idmap.service

To check that everything is running correctly, use the following command:

host# rpcinfo -p

This command displays a list of which rpc ports have been allocated for NFS use.

When the exported directories have been defines, use the following command to view them:

host# showmount --exports

The /etc/exports file

When the 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. The format of the exports file is the same for all versions of the NFS protocol. It contains a list of directory paths, the host (or hosts) to which they are to be exported, together with any additional configuration options.

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 * in the hosts field indicates that the named directory is available to everyone.

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 prevent remote clients accessing your NFS services. When connected to a LAN, the firewall rules can be altered to allow more services to be accessed.

Instead of customizing the firewall rules, the following procedure disables the firewall altogether.

Linux firewall 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

It is also possible to stop this service altogether with the command:

host# /etc/init.d/iptables stop