Linux Tricks and Techniques

For Linux Experts

Use the website for easy leaning of Linux

Monday, 13 February 2017

NFS in Linux


NFS is a feature of Linux operating system by which we can share the files or directories from one Linux host to another Linux host. We can also control the policy of read/write operation on a particular file or directory which we want to share. This is very useful feature as sometimes is saves the space on a host machine because the single host can save the file or directory and can be shared on other system.



Let us consider we have two machines with hostname machine1(10.196.11.1) and machine2(10.196.11.2) and we want to share a directory named /project from machine1 to machine2.

That means machine1 is server and machine2 is client for this file sharing. 

The package required for for the NFS is nfs . which we can check by the command using

# rpm -qa | grep nfs

[root@localhost Desktop]# rpm -qa | grep nfs
nfs4-acl-tools-0.3.3-6.el6.x86_64
nfs-utils-lib-1.1.5-6.el6.x86_64
nfs-utils-1.2.3-39.el6.x86_64


If the package is installed then it is ok otherwise we can install the package using YUM utility.

The configuration file of the NFS is /etc/exports and the services required for this sharing are 

1)nfs - should be enabled on both the machines.
2)nfslock
3)portmap

Now let us consider that we want to share /project directory from machine1 to machine2.

At machine1 

[root@localhost Desktop]# mkdir /project
[root@localhost Desktop]# cd /project/
[root@localhost project]# ls
[root@localhost project]# touch file1 file2
[root@localhost project]# ls
file1  file2


Now go to the configuration file of the machine1 and share the directory in that like:

# vi /etc/exports

/project        *(rw,sync)

save the file and restart the nfs service and other services also

# service nfs restart

# service nfslock start

# service portmap start

At Client

# showmount -e 10.196.11.1

the above command will show the shared files or directories from the server 10.196.11.1 and to access these shared directories we need to mount them on client machine.

(nfs, nfslock, portmap should also be started at client also)

# mkdir /nfs

# mount 10.196.11.1:/project /nfs

# cd nfs

will show the files we have created in /project at machine1.

Thanks.













No comments:
Write comments