Quick Links:
Setting up NFS on CentOS (server and client)
Setting up NFS on CentOS (NFS Server)
Setting up NFS share location CentOS (NFS server)
NFS TCP Wrappers
Configuring the client(s)
Mounting the share CentOS (client)
Auto mounting on server boot
NFS Commands


Server IP:

Client IP: x.x.x.x


NFS Server Configuration:

yum install nfs-utils

Then you want to turn this on from server boot (and start it):

chkconfig rpcbind on

service rpcbind start

You now need to enable nfs lock on the server with the following command:

chkconfig nfslock on

service nfslock start


Setting up the shared location:

For this example I will share the location /var/www/html/ To do this you will need to edit the /etc/exports file and add the following line.

Note: You can replace /var/www/html with what ever location you wish to share. You will also need to replace the x.x.x.x with the clients IP address. The entry can be added multiple times:

/var/www/vhosts x.x.x.x(rw,sync,no_root_squash)



Firewall rules for the NFS server:

On the NFS server make sure you allow the clients ip address in iptables with the following command:

iptables -I INPUT -s x.x.x.x -j ACCEPT


TCP Wrappers

NFS also uses tcp wrappers. You will need to check /etc/hosts.allow and /etc/hosts.deny

People can uses these files to allow or deny ip addresses. If you wish to add a server to the allow then you should edit /etc/hosts.allow with the following code (replacing x.x.x.x with the clients ip)



Configuring the Client

You will need to install the following on the client server to be able to use NFS:

yum install nfs-utils

You will then need to configure the server to start the following from server boot:

chkconfig nfslock on
chkconfig rpcbind on
chkconfig netfs on
chkconfig nfs on

You should then start rpcbind:

service rpcbind start


Mounting the shared location:

On the client you should run the following command, making sure that you replace with the IP address of the NFS server. Note: if you have chosen a different location to share then you will need to change the first /var/www/vhosts to the shared location. You can also mount this in a different location on the client server, for this you will need to replace the second /var/www/vhosts/ in the following command:

mount -t nfs -o noatime,actimeo=3 /var/www/vhosts/

It may take a while to load depending on the size of the shared location. It should return nothing once it has been successfully completed.

You can use the following command to see if it has mounted correctly:

df -h

output should show you something similar to:

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             20G  1.5G   18G   8% /
tmpfs                 496M     0  496M   0% /dev/shm
20G  1.8G   17G  10% /var/www/vhost/

Ip address represents the NFS server and where it the location has been mounted.

Now go to the mounted location and have a look.



umount /path/to/mount


Auto Mounting on server boot

Edit the following file so that the server automatically mounts the NFS: /etc/fstab /var/www/vhosts/ nfs rw,sync,hard,intr 0 0


NFS Commands

showmount -e run this command on your SAN to show all mounts and their server IP address.

nfsstat displays statistics kept about NFS client and server activity.

umount /path/to/mount un-mounts the drive currently mounted. This should be run on the clients machine

df -h run on the client machine will show the mounted locations

mount -t nfs -o noatime,actimeo=3 x.x.x.x:/var/www/vhosts/ /var/www/vhosts/ should be fine on the client machine and will mount shared file location. Please note x.x.x.x should represent the ip address of the NFS server. The first /var/www/vhost/ is the file location of the NFS server and the second is the mount location on the client server.