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( and machine2( 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

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.

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

the above command will show the shared files or directories from the server 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 /nfs

# cd nfs

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


No comments:
Write comments