NFS Crash course

Posted in: General system administration |

I wrote up a quick guide to setting up NFS awhile back but never published it. It is not exactly a nice and clean format but it is exactly what you need to be reading if you want a quick way to setup NFS between two servers. For the purpose of the guide I have added directions for the APF firewall, obviously anything else will work fine.
First make sure the rpms are install
up2date nfs-util portmap
yum install nfs-util portmap

Now start the service:
service portmap start
service nfs-util

*note* if portmap gets an error remote portsentry (cpanel among others installs it)
rpm -e portsentry

Allow portmap in the hosts.allow to access the resources it needs:
echo “portmap:ALL” >> /etc/hosts.allow

Now make the directory we want for nfs
mkdir /nfs
chmod 0777 /nfs -R

Now create the config file
vi /etc/exports

/nfs 123.123.123.123/255.255.255.0(rw,async)
/nfs 321.321.321.321/255.255.255.0(rw,async)

One line for each server that connects, make sure to put the subnet mask. You can put multiple per IP but this is easier for now.

Now restart the nfs service
exportfs -ra

Don’t forget the firewall
apf -a client-IP

Now ssh into the client machine and add this to fstab:

vi /etc/fstab

123.123.123.123:/nfs /var/www/nfs nfs rw 0 0:

/nfs is the shared directory and /var/www/nfs is the mounted directory. Now make the directory

mkdir /var/www/nfs
chmod 0777 /var/www/nfs

Allow portmap in the hosts.allow to access the resources it needs:
echo “portmap:ALL” >> /etc/hosts.allow

Do the firewall
apf -a nfs-server

And mount the NFS:

mount /var/www/nfs

Done :)

Leave a Reply