NFS File Sharing Across Servers

NFS SERVER INSTALLATION AND CONFIGURATIONS

To Install NFS Server:

yum install nfs-utils

After installation, Edit the configuration file to ensure NFS ports are running on static port to enable iptables control later:

vi /etc/sysconfig/nfs
RQUOTAD_PORT=875
# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769
# Port rpc.mountd should listen on.
MOUNTD_PORT=892
# Port rpc.statd should listen on.
STATD_PORT=662
# Outgoing port statd should used. The default is port
# is random
STATD_OUTGOING_PORT=2020

Once configuration is done, start all required services:
systemctl start rpcbind
systemctl start nfs
systemctl start nfslock

Set service auto restart each time system reboot:
systemctl enable rpcbind
systemctl enable nfs
systemctl enable nfslock

Allow internal IPs to access the NFS server via iptables:

iptables -I INPUT -s 10.0.0.0/24 -p udp -m state --state NEW -m udp --dport 662 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 662 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p udp -m state --state NEW -m udp --dport 875 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 875 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p udp -m state --state NEW -m udp --dport 892 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 892 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p udp -m state --state NEW -m udp --dport 32769 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 32803 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT
iptables -I INPUT -s 10.0.0.0/24 -p udp -m state --state NEW -m udp --dport 111 -j ACCEPT

Save the iptables configuration:
iptables-save > /etc/sysconfig/iptables

Next, set the folders to share:
vi /etc/exports

Add in lines like below:

shared-folder *(insecure,rw,async,no_root_squash)
e.g.
/usr/project/share *(insecure,rw,async,no_root_squash)

Run the below command to refrehs the settings done in /etc/exports:
exportfs -ra
systemctl restart nfs

NFS CLIENT SETUP

IMPORTANT NOTE: mount command will remove all files in the mounted folder. Make sure the mount point is unique and nothing is in there!!

New Mount Version Client Commands:

mount -t nfs -o ro server-ipaddress:shared-folder local-destination
e.g.
mount -t nfs -o ro 10.0.0.1:/usr/project/share /www/project/share

Mount on Boot:
vi /etc/fstab
add in line:

server-ipaddress:shared-folder local-destination nfs defaults,_netdev 0 0
e.g.
10.0.0.1:/usr/project/share/ /www/project/share/ nfs defaults,_netdev 0 0

Show mount on client:
mount

Check client to server connection:
showmount -e servername

Be the first to comment

Leave a Reply

Your email address will not be published.


*