Configuring NFS

NFS uses the /etc/exports file for its configuration. We will do a very simple NFS export here, but of course, like everything in Linux, this has a number of configuration options, all of which increase the security - and complexity.

debian:/# cat /etc/exports
# /etc/exports: the access control list for filesystems \
                which may be exported
#               to NFS clients.  See exports(5).

/home   192.168.1.0/255.255.255.0(rw,ro,sync,no_root_squash)
debian:/#
            

The /etc/exports file must contain a directory, (in this example the directory being exported is /home), as well as the networks (or hosts) the file system is exported to.

In this case it's exported a range of hosts in the network 192.168.1.0. Alternately, it could be exported to a single host using the configuration:

/home	192.168.1.24/255.255.255.0(rw,sync,no_root_squash)
            

The export file must not have a space between the host (or network we're exporting to) and the options (enclosed in round brackets).

The most common options are going to be rw meaning read/write, (the drive is exported read-write) or ro, meaning read only, then you synchronize write to the disc and add extra options like no route squash.

[Note] Note

I would encourage you to go and read the man page on exports (man 5 exports) to see what other options you can use.

Once you have finished adding your options, you can then close the round bracket and your file will then export your home directory to the hosts on that network.

Having set up the exports file, it is simply a case of saying /etc/init.d nfs-user-server restart to initiate the changes.

debian:/# /etc/init.d/nfs-user-server restart
Stopping NFS servers: mountd nfsd.
Starting NFS servers: nfsd mountd.
debian:/#
            

That will start the NFS server and now there is nothing more to do from the server side.

From the client's side, we can do a couple of things and really the most important thing is we want to mount the exporter drive on the server.

Do a mount with the IP address 192.168.1.140, in my case this is the IP address of the server - and :/home.

I'm going to mount this directory on this server and I'm going to mount it on /mnt/nfs server (this directory needs to be created before you can mount the NFS drive to it.)

linux:/ # ls /mnt
.  ..
linux:/ # mkdir /mnt/debian
linux:/ # ls /mnt/debian/
.  ..
linux:/ # mount 192.168.10.144:/home /mnt/debian
linux:/ # ls /mnt/debian/
.    bazaar.txt   dir1         emails3.txt  foo      guest
..   columns.txt  emails1.txt  file.txt     foo.txt  hamish
bar  contact.txt  emails2.txt  file1        foo2     mem.stats
linux:/ #
            

Now in fact this is just a mount point like every other filesystem needing a mount point.

Once mounted run a "df -h" command which should show you the mounted drive and the server should be the home directory that we exported from the server should be mounted on /mnt/debian.