Install the NFS packages:
# yum groupinstall -y "NFS file server"
Add new rules to the firewall:
# iptables -I INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT # iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT # iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
Save the firewall configuration:
# service iptables save
Activate the NFS services at boot:
# chkconfig rpcbind on # chkconfig nfs on # chkconfig nfslock on
Start the NFS services:
# service rpcbind start # service nfs start # service nfslock start
Create directories to export and assign access rights:
# mkdir -p /home/tools # chmod 777 /home/tools # mkdir -p /home/guests # chmod 777 /home/guests
Edit the /etc/exports file and add the following lines with the name (or IP address) of the client(s):
/home/tools client1(rw,no_root_squash) /home/guests client2(rw,no_root_squash)
Note: Please, don’t put any space before the open parenthesis, this would completely change the meaning of the line!
Export the directories:
# exportfs -avr
Note: On the client side, the commands are:
# yum install -y nfs-utils # mount -t nfs server:/home/tools /mnt
Thanks for creating this tutorial.
I thought that the remote file system needed to be mounted on the client end
[root@client2]# mount -t nfs host:/home/guests/ /shared
Yes, you are right but this tutorial shows the server side configuration.
It is clear that the client needs to mount or automount the fs from the NFS server to be able to use it.
A major source of confusion for many people is whether it is still necessary to go into /etc/sysconfig/nfs and specify ports for mountd, lockd, and statd, and then update the iptables rules with these ports.
This is only necessary if you are running NFSv2 or v3.
As specified in this guide, one only needs to open tcp-111, udp-111, and tcp-2049 when running NFSv4 on RHEL6.