Wednesday, February 16, 2011

Sharing a directory using nfs

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 of the file is:
dir_to_be_exported allowed_hosts(options)
I am just about to export my home dir and allowing only 192.168.2.10 to 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 the 192.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 nfs server would actually show you which clients have mounted the exported directory.

No comments:

Post a Comment