Skip to main content

How to setup nfs server on centos 6


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 .
[[email protected] ~]# 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.
[[email protected] ~]# service rpcbind start
[[email protected] ~]# service nfs start
[[email protected] ~]# chkconfig nfs on && chkconfig rpcbind on

Step 3 » Create a directory /shome.
[[email protected] ~]# mkdir /shome
Step 4 » Now add the configuration details to /etc/export file which is the config file for NFS.
[[email protected] ~]# vim /etc/exports

and see the other examples

Step 5 » Export the shares using the below command.
[[email protected] ~]# exportfs -a
Step 6 » Verify the shares
[[email protected] ~]# exportfs -v
/shome (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.
[[email protected] ~]# service iptables stop
if you want to stop permanently
[[email protected] ~]# 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
[[email protected] ~]# yum install nfs-utils nfs-utils-lib
Step 2 » Create a directory /rhome ( Home directory for the users ).
[[email protected] ~]# mkdir /rhome
Step 3 » Now mount the remote share shome directory on rhome local directory.
[[email protected] ~]# 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 0File will looks like

Step 4 » Take a quick look on mounted share by using mount command. The last line shows, remote nfs share is mounted properly.
[[email protected] ~]# 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 .
[[email protected] ~]# useradd -d /rhome/krizna krizna
This will create home directory for user krizna in rhome directory.

On Client – Ubuntu

Step 1 » Install nfs and dependencies packages.
[email protected]:~$ sudo apt-get install nfs-common rpcbind
Step 2 »Same thing here. Create a directory rhome on / ( This can be a home directory).
[email protected]:~$ sudo mkdir /rhome
Step 3 » Now mount the remote share .
[email protected]:~$ sudo 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
Step 4 » Check the mounted share using mount command.
[email protected]:~$ mount
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
192.168.1.10:/shome on /rhome type nfs (rw,vers=4,addr=192.168.1.10,clientaddr=192.168.1.201)

Step 5 » create a user by pointing home directory to rhome directory .
[email protected]:~$ useradd -d /rhome/testubuntu testubuntu
Now on server you can see 2 home directories “krizna” and “testubuntu” in shome directory .
Have a nice day.