Getting Started With Networking for Linux Part 3; Sharing File Systems

Josh Boudreau returns to Linux.com Learn with the third part of his popular introduction to networking series. In part three of Getting Started with Networking for Linux Josh takes a look at sharing file systems between Windows and Linux boxen on the same network, using technologies like Samba and smbmount.

Introduction

Welcome to the third installment of the Getting Started With Networking
for Linux series. In the previous articles we covered networking
hardware, basic TCP/IP
configuration and how to implement DNS (Domain Name
System) for your network. While this article doesn't necessarily
require knowledge of the previous topics, it would be a good idea to
read the other articles first if you are new to networking in general.

Today we're going to see how you can share and mount remote file systems
across your network using NFS (Network File System). We will also see
how to use Samba to make sharing and accessing Microsoft Window file
systems a possibility. If you haven't experimented with this type of
service before you will find that having access to the data of all the
computers on a network from one single computer is a very handy service.
The idea behind this service is that when a file system is shared on a
network, any computer with the correct permissions can mount that file
system locally and read/write data from it just like you manage data on
your local hard drive.

In the Unix world the NFS service is used to export and mount file
systems. NFS is a standard Unix service and chances are it's already
installed on your machine. Microsoft Windows machines don't use the NFS
service and instead they export file systems using the SMB protocol that
is common among Microsoft Window machines. To export and mount Microsoft
Windows shares we are going to use Samba, which is an open source
software package that allows Linux to use the SMB protocol. Samba may or
may not be installed by default on your Linux distribution but in any
case you can get the software from www.samba.com.

Exporting File Systems With NFS

The NFS configuration file used to export file system directories to
other computers is the /etc/exports file. This file
contains a table of exported directories and which computers on your
network have access to them. Here's a listing an example NFS
configuration file:

As you can see, there are numerous ways to export directories to all or
only a few computers. The first column lists the directories that you
want to export. The second column lists the hosts that have access to
that directory and the permissions they get granted. You can list hosts
with IP addresses, DNS domains with wild cards, IP subnets and
hostnames.

The last entry in our example file is a special one. It exports the
/home/ftp/pub directory to everybody, even to hosts not on
part of your network. The permissions for each host if put after its
entry in parenthesis with (ro) being read-only and
(rw) being read/write. Many other options (like mapping of
user and group ids) can also be put inside the parenthesis. For a
complete list of options read the exports(5) man page by typing
man 5 exports at your shell prompt.

One thing to note is that DNS wild cards don't match the dots in domain
names. This means that having *.domain.lan as a host in
your /etc/export file won't give access to computers with
domains like subnet.domain.lan. To match those domains you
need to specifically add them like *.subnet.domain.lan.

Once you have tailored your /etc/exports file to your taste
you must restart the NFS daemon for the changes to take effect. On Linux
the NFS file systems are handled by the rpc.mountd and
rpc.nfsd daemons. You must restart both of these daemons to
have your directories exported. You can restart them by typing the
following commands:

killall -HUP rpc.mountd
killall -HUP rpc.nfsd

Mounting Remote NFS File Systems

Now that we have our directories exported let's see how to mount them
from another machine. The process of mounting NFS file systems is almost
the same as mounting local hard drives or cdroms. You must first have a
mount point to access the file system once it's mounted. A common place
to put mount points is in the /mnt directory. Mount points
are simply directories, so all you need to do is mkdir
/mnt/mountpoint to create one.

mkdir /mnt/remote_cdrom
mkdir /mnt/josh_mp3
mkdir /mnt/ftp_pub

Typing the above commands would create three directories in
/mnt. Now that we've got mount points let's mount the file
systems. For example, say that the computer we have exported the
directories on is at IP address 192.168.1.98 and has a
domain of node98.domain.lan; the following commands would
mount the exported directories on our local machine (assuming we have
the correct permissions in the server's /etc/export file).

Instead of telling mount to use a local device like we usually do when
mounting hard drives or cdroms, we put a hostname or IP address followed
by a colon and the exported directory on the target computer. After
mounting those three directories you can read and write data to them
like normal directories on your local file system. If you try to mount a
directory on which you have no permissions you will get a
permission denied error. If you get this error check the
remote computer's /etc/export file to make sure the
computer trying to access the directory is listed. If you get a
RPC TimeOut error this means that the
rpc.mountd and rpc.nfsd daemons might not be
running so be sure to check that they are in fact running by typing
ps ax on the NFS server. The rpc.nfsd and
rpc.mountd also need the rpc.portmap daemon so
they can make rpc calls across the network and this might also be the
reason you're getting a RPC TimeOut error.