SETTING UP FILE SHARING WITH NFS

Despite the popularity (and Windows compatibility) of Samba, NFS is often a preferred software choice for sharing files amongst several Linux machines. Below, we discuss how to set up a copy of NFS on your system.

As root, edit your /etc/exports file. Here is an example file:

/home comp1(rw), comp2(rw), master(rw,no_root_squash) /mnt/cdrom comp2(ro)

This shares /home (and all subdirectories) with the computers comp1, comp2, and master (each should be defined in your /etc/hosts file). Both comp1 and comp2 are allowed Read/Write permissions, and so is master, but master is also allowed to manipulate the volume as root. Typically, NFS will squash all root commands, effectively disallowing them. But for the machine master, the root commands will be allowed. The /mnt/cdrom volume is only available to comp2, and even then it is only allowed as read-only.

On the client side, let's say for comp2, you could put the following in your /etc/fstab file to mount the NFS shares:

server:/home /mnt/home nfs

noauto,rsize=8192,wsize=8192,user,exec 0 0

server:/mnt/cdrom /mnt/cdrom2 nfs

noauto,rsize=8192,wsize=8192,user,exec 0 0

What this does is mount the /home share on the machine called server to the mount point /mnt/home. It also mounts /mnt/cdrom on server to the directory /mnt/cdrom2. By specifying noauto as an option, it won't be mounted automatically on boot but can be mounted any other time by using:

# mount /mnt/home

Of course, you must have the NFS server tools installed on server and the NFS client tools installed on the client systems, but most Linux systems come with both preinstalled.