This guide explains how to setup NFS Server and NFS client on Centos 7.

NFS (Network File System) is a popular file system protocol which allows users to share folders/directories across Linux machines and can be able to mount them permanently on their Linux servers.

Any changes made on the NFS server will automatically be replicated to the NFS Client servers.

Advantages & Uses of NFS

  • Used to share files/folders between Linux Systems
  • Allows you to mount Remote filesystems Locally.
  • It acts a central storage.

To Setup the Environment We need Two Servers

One for NFS Server and One for NFS Client running centos/redhat 7.

Server Side

As a first step, We need to install NFS packages in the NFS server.

#yum install nfs-utils -y

Now, We are going to create a directory to share with client servers. Here I will be creating a new directory named “test” in “/” partition.

Note: You can also share your existing directory with NFS.

#mkdir /test

Now change the permission of the folder as follows:

#chmod -R 755 /test

#chown nfsnobody:nfsnobody /test

Next, We need to start the NFS services required and enable them to be started at Boot time.

  • #systemctl enable nfs-server
  • #systemctl enable rpcbind
  • #systemctl enable nfs-lock
  • #systemctl enable nfs-idmap
  • #systemctl start nfs-server
  • #systemctl start rpcbind
  • #systemctl start nfs-lock
  • #systemctl start nfs-idmap

Now We will share the NFS Directory over the network as follows:

It is the main configuration file,  controls which file system to be shared remotely.

#vi /etc/exports


Note: is the IP Address of the client Machine, We can also use a hostname instead.We can also share the directory to entire subnet like

rw – writable permission to the shared folder.

sync – all the changes are immediately replicated.

no_root_squash – If this option is included, the root on the NFS client machine has the same level of permission to the root in the NFS server.

Export the shared directory using the following command:

#exportfs -a [Exports all the directories listed in /etc/exports]

Now restart the NFS sevice:

#systemctl restart nfs-server

Configure Firewall

We need to configure firewall on the NFS server to allow the NFS clients to access the shared directory.To do that, Run the following commands:

First Install firewall-cmd packages If not there.

#yum install firewalld -y

#systemctl start firewalld

  • #firewall-cmd –permanent –zones=public –add-service=mountd
  • #firewall-cmd –permanent –zones=public –add-service=rpc-bind
  • #firewall-cmd –permanent –zones=public –add-service=nfs
  • #firewall-cmd –reload

Configuring NFS Client

We need to install NFS packages on the client servers to mount the remote filesystem using the below commands:

#yum install nfs-utils libnfsidmap -y

Once installed, Enable and start the NFS services.

#systemctl enable rpcbind

#systemctl start rpcbind

Now create a directory, Where you want to mount the shared folder from the NFS Server.

#mkdir /share

Use the below command to mount the shared directory /test to /share directory in NFS client.

#mount /share

Where is the NFS server’s IP Address.

You can verify the mounted share on the client using “mount” command:

#mount |grep nfs

You can also verify the same using the below command:

#df -Th

Now create a test file on the shared directory to verify the Read and Write Access on the NFS share.

If the above command returns no error, Then You have the working NFS setup.

To Mount NFS Share Permanently

To mount the shared directory automatically after every reboots, We need to edit /etc/fstab in the Client Server.

#vi /etc/fstab [Open this file and add the below line] /share nfs rw,sync,hard,intr 0 0

save and close the file.

Reboot the machine to check whether the shared directory is automatically mounted or not.

If you want to unmount the shared directory from your client server. Run the below command:

#umount /share.

That’s All.You have successfully Setup NFS Server and Client on Centos 7 / Redhat 7.