Configuring a NFS server

After having updated the Debian Sarge ISO images with http://digen.wordpress.com/2006/04/24/jigdojigsaw-download/ I wanted to transfer them to my desktop computer running Fedore Core 5, simply because I was running out of hard disk space. :( Configuring a NFS server on my Ubuntu machine would allow me to transfer data to the desktop machine running FC5.

Incase anyone would like to know more about a Network File System(NFS) server then head over here : http://en.wikipedia.org/wiki/Network_File_System
The required packages for Debian are

1.portmap
2.nfs-common
3.nfs-kernel-server
In case of a Redhat/Fedora distro the packages would be
1.portmap
2.nfs-utils

Installing packages with apt is as simple as this,

swapneel@ubuntu:~$ sudo apt-get install portmap nfs-common nfs-kernel-server
Reading package lists… Done
Building dependency tree… Done
portmap is already the newest version.
nfs-common is already the newest version.
nfs-kernel-server is already the newest version.

I've already installed the required packages.
The main configuration file to setup NFS in any GNU/Linux box is /etc/exports.The configuration file would be blank by default unless it has been configured.

Open the /etc/exports file in any editor of your choice,I prefer Vi
The syntax of the file is

/home/jigdo/ 192.168.1.0/255.255.255.0(ro,sync)

The above simply means I want to export the /home/jigdo/ directory to all computers in the 192.168.1. subnet with the options "read only" & "sync" on the exported NFS share.

*You could use wildcards & further fine tune the computers you want the NFS share to be shared with.For more information on the various options available read the exports man page.

My home network is in the 192.168.1. subnet or I could have defined it in other way,

/home/jigdo 192.168.1.106/255.255.255.0(ro,sync)

The above would allow only the computer with the IP address 192.168.1.106 to export the share from the NFS server.
Another thing to note is for rw support,that is writing on the NFS share from a remote NFS client the permissions on the share as well as file system permissions on the directory should be rw.

To update the NFS server's share listing

swapneel@ubuntu:~$ sudo exportfs -r

To view the directories shared along with options

swapneel@ubuntu:~$ exportfs -v
/home/jigdo 192.168.1.0/255.255.255.0(ro,wdelay,root_squash)

The root_squash option prevents root access if any remote NFS client tries to access the NFS share with the root account.

Setting up the client NFS:

On the remote client you could get the list of directories exported by the NFS by issuing the following command

[root@station1 ~]# showmount -e 192.168.1.27
Export list for 192.168.1.27:
/home/jigdo 192.168.1.0/255.255.255.0

The above simply shows the exports on the NFS server with the IP address 192.168.1.27.

Now the only step remaining is to mount the exported directory on the client local filesystem by using the mount command,

[root@station1 ~]# mount 192.168.1.27:/home/jigdo/ /root/nfs/

The /home/jigdo export share has been mounted from the server with the IP address 192.168.1.27 on the local directory /root/nfs/

The mount command without any options confirms the mounting of the NFS export share being successful,

192.168.1.27:/home/jigdo/ on /root/nfs type nfs (ro,addr=192.168.1.27)

The above exported share can be mounted across persistent reboots by manually entering the below in the /etc/fstab file.

192.168.1.27:/home/jigdo/ /root/nfs nfs defaults,soft 0 0

The option 'soft' wont hang the nfs client if the nfs server is unavailable,instead it will return a error.

The above is the easiest way I could think of to transfer data between GNU/Linux computers.There maybe other ways to do what I've written about.Feel free to point out mistakes if any,comments & suggestions are always welcome.


About this entry