This is a very basic step-by-step guide to create a CentOS7 NFS server that shares a folder /nfsshare over 192.168.4.0/24 network. This share will be owned by apache and mountable on a CentOS web server.
Here the instructions how to create the server and how to setup the client.
NFS Server
Add this line in IPTABLES:
-A INPUT -s 192.168.4.0/24 -m comment --comment "NFS Network" -j ACCEPT
Run the following to create a share folder and setup NFS:
mkdir /nfsshare yum install nfs-utils nfs-utils-lib -y systemctl enable nfs-server echo "/nfsshare 192.168.4.0/24(rw,sync,no_root_squash)" >> /etc/exports sed -i 's/#Domain = local.domain.edu/Domain = nfsdomain.loc/' /etc/idmapd.conf systemctl start rpcbind systemctl start nfs-server # Create apache user/group # (NFS clients will read/write using this user so we want to have # the same set also on the server for an easier ownership management) groupadd -g 48 apache useradd -g 48 -u 48 apache
NFS Client
e.g. assuming that NFS server’s IP is 192.168.4.1
Add this line in IPTABLES:
-A INPUT -s 192.168.4.0/24 -m comment --comment "NFS Network" -j ACCEPT
Then, run this:
yum install nfs-utils rpcbind sed -i 's/#Domain = local.domain.edu/Domain = nfsdomain.loc/' /etc/idmapd.conf echo "192.168.4.1 NFS01" >> /etc/hosts mount -t nfs4 -o noatime,proto=tcp,actimeo=3,hard,intr,acl,_netdev NFS01:/nfsshare tail -1 /proc/mounts >> /etc/fstab
NOTE: we are hardly mapping the NFS server’s IP in /etc/hosts to make easier to recognise the mount (in case of multiple mounts).
If you are facing the issue where you mount /nfsshare and you see the owner of the files and folders showing as nobody:nobody, it could be related to rpcidmapd and DNS. To fix this, try to update /etc/hosts on the Client with <hostname>.nfsdomain.loc
# ============= # # Ubuntu Notes # # ============= # !! Same users on Server and Client - for the exported partition !! SERVER apt-get install nfs-kernel-server vim /etc/exports /var/www/vhosts 192.168.3.*(rw,sync,no_root_squash,no_subtree_check) service nfs-kernel-server restart exportfs -a CLIENT apt-get install nfs-common mount -t nfs4 192.168.3.1:/var/www/vhosts /var/www/vhosts/ !! CHECK the output of cat /proc/mounts and you can get the correct rsize/wsize. If the firewall/network can handle, keep this value as big as possible: e.g. noatime,proto=tcp,actimeo=3,hard,intr,acl,_netdev,rsize=1048576,wsize=1048576 vim /etc/fstab 192.168.3.1:/var/www/vhosts /var/www/vhosts nfs4 noatime,actimeo=3,hard,intr,acl,_netdev,rsize=32768,wsize=32768 0 0