How to Install and Configure NFS Server in CentOS 6 / 7

What is NFS?
NFS is a network file system, which allows remote hosts to mount file system over a network and interact with those file systems as though they are mounted locally.

Why we use NFS?
NFS is used for sharing files and directories over  the network.

Server Information
Server IP Address:  192.168.0.65/24
Client IP Address:  192.168.0.68/24

Package required for NFS
nfs-utils 

Configuration file
/etc/exports

Port No for NFS:
2049: nfsd

NFS option meaning
/directory_name :  Share directory
192.168.0.68: Specify ip address of client allowed in nfs configuration
 192.168.0.0/24 : Allow IP address range for client
rw  : Read/Write permission to Shared directory
ro : Read only permission to shared directory
sync : synchronize share directory
no_root_squash : Enable for root privileges
no_all_squash:  Enable user authority
no_subtree_check: Occasionally, subtree checking can produce problems when a requested file is renamed while the client has the file open. If many such situations are anticipated, it might be better to set no_subtree_check. One such situation might be the export of the /home filesystem. Most other situations are best handed with subtree_check.

Installation NFS package on server
[root@server ~]# yum install nfs* -y

Configure NFS Server
Create directory which you want to share
[root@server ~]# mkdir /share
Now, share directory in config file
[root@server ~]# vim /etc/exports
/share *(rw,sync,no_root_squash,no_subtree_check)
Or,
/share  192.168.1.1/24 (rw,sync,no_root_squash,no_subtree_check)
Or,
/share  client.kvit.in (rw,sync,no_root_squash,no_subtree_check)
Or,
/share   192.168.0.69(rw,sync,no_root_squash,no_subtree_check)

Start NFS service in CentOS 6
[root@server ~]# service nfs start
[root@server ~]# service rpcbind start
[root@server ~]# chkconfig nfs on
[root@server ~]# chkconfig rpcbind on

Start NFS service in CentOS 7
[root@server ~]# systemctl start rpcbind nfs-server
[root@server ~]# systemctl enable rpcbind nfs-server
 
Troublshtooing
Check the status of running portmap service
# rpcinfo –p
Or,
#rpcinfo p 192.168.0.65

If Error: 
rpc.nfsd unable to set any sockets for nfsd
[root@server ~]# yum install avahi
Again Check the rpcbind service works perfectly or not
[root@server ~]# rpcbinfo -p