Thursday, December 18, 2008

NFS

Square brackets are used to separate keywords, such as filenames,
programs names etc, from lines of text. They have no other meaning.

NFS - Network File System : NFS service running in the local machine
provides distributed directory access and allows users of remote hosts
to mount file system of the local machine. To the remote user, the
mounted file system act and appear as if they are local. The file
system is made available by the local machine to the users of remote
machine by exporting the file system. The manner in which the files
are exported and their access, is controlled by entries in the file
[/etc/exports].

The following daemons are needed to provide NFS service.

rpc.portmap - When an RPC ( Remote Procedure Call ) server is started
( such as rpc.nfsd ), it will tell [portmap] what port
number it is listening to, and what RPC program numbers
it is prepared to serve. When a client wishes to make
an RPC call to a given program number, it will first
contact [ portmap ] on the server machine to determine
the port number where RPC packets should be sent.
[portmap] listens on Port-111( TCP/UDP )


rpc.mountd - It is a RPC server that answers a client request to
mount/unmount a file system in the server.

rpc.nfsd - This is the NFS server daemon.

rpc.lockd - This program starts the NFS lock manager ( NLM ) on
kernels that don't start it automatically. Most kernels
start it automatically. Moreover recent [ rpc.nfsd ]
calls [rpc.lockd] on demand. [rpc.lockd] is usually not
required to be started. Even so, running it anyway is
harmless.

rpc.statd - This daemon is used by the NFS file locking service,
[ rpc.lockd ] to implement lock recovery when the NFS
server machine crashes and reboots.

rpc.rquotad - This RPC server returns quotas for a user of a local
file system which is mounted by a remote machine over
the NFS. This not essential for server configuration.
It is not used in this experiment.

Create a directory NFS in your home directory and do the assignments
in that directory.

Complete Assignment-1.

NFS Installation:
Remove previous installation of NFS, if any
# dpkg -r nfs-user-server

Bring the following package in your NFS directory.
Filenames --->
/pool/main/n/nfs-user-server/nfs-user-server_2.2beta47-12_i386.deb on
CD-2

NFS binary package is to be installed in Assignment-2.

Complete Assignment-2.

Mounting NFS file system from client machine:
In Assignment-3, the
localhost is used as the client machine.

The client machine must have support for [nfs] file system. The output
of the following command should contain the string [nfs].
$ cat /proc/filesystems | grep nfs
output --> nodev nfs

The NFS file system on the server can be mounted in the client machine
by [mount] command directly or by an entry in the [ /etc/fstab ] file.

In Assignment-3, mounting is done with [mount] command. This command
need superuser privilege.

Complete Assignment-3.

In Assignment-4, mounting is done with help of an entry in the file
[/etc/fstab].

Complete Assignment-4.

Read manual [nfs(5)] to see the syntax of [fstab] entry for NFS.
You may read manual [mount(8)].

Read NFS-HOWTO, section 6, for security issues involved.

In Assignment-5, another machine in your LAN is used as the client
machine.

Complete Assignment-5.
-------------------------------------------

Assignment-1:
Find out whether [portmap] program is running.
$ ps ax | grep portmap

Is portmap running ? ( Y / N )
Is mountd running ? ( Y / N )
Is nfsd running ? ( Y / N )
Is statd running ? ( Y / N )
Is lockd running ? ( Y / N )
Is rquotad running ? ( Y / N )

Note: If [/etc/exports] file is empty, [nfsd] does not start.

Ask the [ portmapper ] running on localhost, by using the following
command, to print a list of all registered RPC programs and study the
output. You need not record the output.

$ rpcinfo -p localhost

Assignment-2.
Install [nfs-user-serve] and record the screen output.

# dpkg -i nfs-user-server_2.2beta47-12_i386.deb






Examine the output of this command. You need not record it.
# dpkg --status nfs-user-server

Edit [/etc/exports] to contain the following line
#......./etc/exports.........
/tmp *(rw,insecure)
#............................
The directory tree [/tmp] is exported.
[*] - Host wildcard. It indicates that [ /tmp ] in the server
machine can be exported to any host.
[rw] - Means that [ /tmp ] has read and write access. This is a
very loose permission used for illustration only.
[insecure] - This option allows client request to originate from an
Internet port less 1024.

Read manual [exports(5)] other options.

Start [nfsd]. Typical output is shown
# /etc/init.d/nfs-user-server restart
Stopping NFS servers: mountd nfsd.
Starting NFS servers: nfsd mountd.

Typical output of the following command is shown
$ rpcinfo -p localhost
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100021 1 udp 1027 nlockmgr
100021 3 udp 1027 nlockmgr
100003 2 udp 2049 nfs
100003 2 tcp 2049 nfs
100005 1 udp 793 mountd
100005 2 udp 793 mountd
100005 1 tcp 796 mountd
100005 2 tcp 796 mountd

Add the followimg line in [/etc/hosts.allow], in case the [rpc.satad]
uses [tcpd].
ALL: ALL

Assignment-3:
Login to your account. Descend into [ NFS ] directory.
you $ cd NFS
NFS $ mkdir ./remote-dir

Become [root] and mount the directory exported by NFS server(localhost
in this assignment).
# mount -t nfs localhost:/tmp ./remote-dir

Descend into [./remote-dir] and copy [/etc/passwd] in it

remote-dir $ cp /etc/passwd ./

Try to find difference in the directory trees [/tmp] and
[/home/you/NFS/remote-dir]
$ diff /tmp /home/sumit/NFS/remote-dir/

Was there any difference ? ( Y / N )

Record the [nfs] related line from the output of this command.
# mount



Unmount NFS file system
# umount ./remote-dir/

Check successful un-mounting with
# mount or $ mount

Assignment-4:
Save the existing [/etc/fstab] file before making changes
# cp /etc/fstab /etc/fstab.org

Make a mount point in the client machine(localhost in this assignment)
# mkdir /nfs-mount-point

Add the following line in [/etc/fstab] in client machine ( localhost)
127.0.0.1:/tmp /nfs-mount-point nfs rw,user


[127.0.0.1:/tmp] - This field indicates the IP address of the NFS
server and the directory tree that is exported by
the server. [ localhost ] is the server in this
example.

The [mount] command can now be used by an ordinary user of client host
to mount the NFS directory.
$ mount /nfs-mount-point/

Record the output of the following command.
$ mount | grep nfs



Change permission of the previously copied file.

$ chmod 0007 /nfs-mount-point/passwd

Unmount NFS file system
$ umount /nfs-mount-point

Check un-mounting
$ mount

Assignment-5:
Note down the IP address of another machine to be used as
the client machine.

Your machine(192.168.10.10) is the NFS server.

In the NFS server do the following.
Create a directory [/public]. Create a subdirectory [sumit] in it.
# mkdir /public
# mkdir /public/sumit
Copy some files in the directories.
# cp /etc/passwd /public/
# cp /etc/hosts /public/
# cp /etc/hosts.allow /public/sumit/

Enter the following line in [/etc/exports] of NFS server.
#.............. /etc/exports of server ........
/public/ 192.168.10.9(rw,sync,all-sqush)
/public/sumit/ 192.168.10.10(noaccess)
#..............................................
Replace [192.168.10.9] with the IP address of client machine.
[/public/] can be mounted from client host [192.168.10.9] but
[/public/sumit/] would be inaccessible.

Restart the server
# /etc/init.d/nfs-user-server restart



Client machine:
Request the [ root ] user of the client machine to create a directory
[/nfs-tmp].

Request the [root] user of client machine to add the following entry
in [ /etc/fsatb ] of that machine.

192.168.10.10:/public /nfs-tmp nfs rw,user



As any user in the client machine, mount the NFS file system
tom $ mount /nfs-tmp

As user [tom] do the following.
$ cd /nfs-tmp/
$ cp /etc/passwd ./
$ chmod 0700 ./passwd
$ cd sumit
Try to see the files of the [sumit] directory.
Can the files be seen, except [. and .. ] ? ( Y / N )

Unmount NFS file system
$ umount /nfs-tmp

Request the [root] user of the client machine to remove the entry from
[/etc/fstab] and delete the directory [/nfs-tmp].

In the server machine restore the original [/etc/fstab] file.

Optional Assignment:
Download [nfs-kernel-server] source code,compile
and install NFS service.Install access control with [tcpd].
Test access from client machine using both UDP and TCP.