Wednesday, April 11, 2012

Sharing a directory using NFS

This tutorial will walk you through exporting a directory so that we
can read from or write to it. I will make it really simple so that in
emergency situations, you are good to go within a few minutes
First install nfs server (I am on Debian 5.0, other distributions
would have a the nfs package name similar to that)
aptitude install aptitude install nfs-kernel-server
After we have the nfs server installed, you need to export the
directory by using the /etc/exports file. The format ofthe file is:
dir_to_be_exported allowed_hosts(options)

I am just about to export my home dir and allowing only 192.168.2.10to
mount it, so in /etc/exports, I would the following:
/home/linuxgravity 192.168.2.10(rw,sync,no_subtree_check)
That's it. That was so easy, isn't it.
Restart nfs server:
/etc/init.d/nfs-kernel-server restart
Now it is time for us to mount the shared (exported) directory to
mount it on an empty directory. So while in the192.168.2.10, first we
would create a directory
mkdir /home/remote_home
Now just mount it with the following magically command:
mount 192.168.2.2:/home/linuxgravity /home/remote_home
As you have already figured out, the format is mount
nfs_server_ip:exported_dir mount_point
And now you can just read from/write to /home/remote_home easily.
The whole process takes only less than two minutes.
Tip: showmount command on nfsserver would actually show youwhich
clients have mounted theexported directory.

No comments:

Post a Comment