NFS ( Network File System ) is used to share a directory with other clients over a network. It is very useful when it is implemented for accessing shared home folders .

NFS configuration on centos 6 is very easy .Here we need a server and few client machines.

For Demonstration:

Server ( Centos ) : 192.168.1.10

Client ( Centos ) : 192.168.1.200

Client ( Ubuntu ) : 192.168.1.201

Setup nfs server on centos 6

Let’s start. First we need to setup server on centos 6. For my requirement i’m going to create /shome directory on server to store users home directories.

On Server – Centos

Step 1 » Issue the below command to install nfs and dependencies .

[root@server ~]# yum install nfs-utils nfs-utils-lib

Step 2 » After installation issue the commands one by one to start the services and make them to start automatically on boot.

[root@server ~]# service rpcbind start

[root@server ~]# service nfs start

[root@server ~]# chkconfig nfs on && chkconfig rpcbind on

Step 3 » Create a directory /shome.

[root@server ~]# mkdir /shome

Step 4 » Now add the configuration details to /etc/export file which is the config file for NFS.

[root@server ~]# vim /etc/exports

#Share access to all networks /shome *(rw,sync,no_root_squash,no_subtree_check) 1 2 #Share access to all networks / shome * ( rw , sync , no_root_squash , no_subtree_check )

and see the other examples

#Share access to particular network /shome1 192.168.1.1/24(rw,sync,no_root_squash,no_subtree_check) #Share access to particular host /shome2 host.example.com(rw,sync,no_root_squash,no_subtree_check) /shome2 192.168.1.200(rw,sync,no_root_squash,no_subtree_check) #Share access to all hosts in particular domain /shome3 *.krizna.com(rw,sync,no_root_squash,no_subtree_check) 1 2 3 4 5 6 7 #Share access to particular network / shome1 192.168.1.1 / 24 ( rw , sync , no_root_squash , no_subtree_check ) #Share access to particular host / shome2 host . example . com ( rw , sync , no_root_squash , no_subtree_check ) / shome2 192.168.1.200 ( rw , sync , no_root_squash , no_subtree_check ) #Share access to all hosts in particular domain / shome3 * . krizna . com ( rw , sync , no_root_squash , no_subtree_check )

Step 5 » Export the shares using the below command.

[root@server ~]# exportfs -a

Step 6 » Verify the shares

[root@server ~]# exportfs -v

/shome <world>(rw,wdelay,no_root_squash,no_subtree_check)

/shome1 192.168.1.1/24(rw,wdelay,no_root_squash,no_subtree_check)

/shome2 192.168.1.200(rw,wdelay,no_root_squash,no_subtree_check)

/shome3 *.krizna.com(rw,wdelay,no_root_squash,no_subtree_check)

Now stop iptables for testing.

[root@server ~]# service iptables stop

if you want to stop permanently

[root@server ~]# chkconfig iptables off

later check this post Iptables for nfs server on centos-6 and apply rules to allow nfs shares in Iptables.

On Client – Centos

These steps can be applicable for redhat and fedora.

Step 1 » Install nfs and dependencies

[root@client ~]# yum install nfs-utils nfs-utils-lib

Step 2 » Create a directory /rhome ( Home directory for the users ).

[root@client ~]# mkdir /rhome

Step 3 » Now mount the remote share shome directory on rhome local directory.

[root@client ~]# mount 192.168.1.10:/shome /rhome

open /etc/fstab file and add the following line for permanent mount.

192.168.1.10:/shome/ /rhome/ nfs rw,sync,hard,intr 0 0 File will looks like

devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 192.168.1.10:/shome/ /rhome/ nfs rw,sync,hard,intr 0 0 1 2 3 4 devpts / dev / pts devpts gid = 5 , mode = 620 0 0 sysfs / sys sysfs defaults 0 0 proc / proc proc defaults 0 0 192.168.1.10 : / shome / / rhome / nfs rw , sync , hard , intr 0 0

Step 4 » Take a quick look on mounted share by using mount command. The last line shows, remote nfs share is mounted properly.

[root@client ~]# mount

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

192.168.1.10:/shome on /rhome type nfs (rw,vers=4,addr=192.168.1.10,clientaddr=192.168.1.200)

Step 5 » For testing , just create a file in rhome directory and same file can be found on server shome directory.

Additionally you can create a user by pointing home directory to rhome directory .

[root@localhost ~]# useradd -d /rhome/krizna krizna

This will create home directory for user krizna in rhome directory.

On Client – Ubuntu