< All Docs

How to Setup NFS server on CentOS

Create a Microhost account to try this guide with a $50 credit.

Table of Content

What is NFS server

NFS (Network file Sharing) is a protocol used to share files and directories with other linux users.An NFS share is mounted on a client machine. NFS service uses port Number 2049  

For creating NFS server on client machine we have to install nfs-utils tool on server as well as on client machine also for installing nfs-utils tool on server use 

Server side configuration.

# yum install nfs-utils

After installation, we have to start and enable nfs-server.service 

# systemctl start nfs-server.service
#systemctl enable nfs-server.service
Note: For starting and enabling nfs-server.service “rpcbind” service must be enabled and started 

Now, if you are using a firewall on the server, allow nfs,mountd,rpc-bind and after adding services in the firewall reload the firewall service.

# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --permanent --add-service=mountd

# firewall-cmd --reload

After making these changes in firewall configuration you can check the configuration by using the following command

# firewall-cmd --list-all

Now select the directory which you want to share with client machine, in this case i am going to create nfsshare directory under the root directory.

#mkdir /nfsshare

Now, make the changes in permission and ownership directory /nfsshare

#chown nfsnobody:root /nfsshare
#chmod 777 /nfsshare

Now add the configuration in /etc/exports 

# vi /etc/exports

Add the following content in the file

<export> <host1>(<options>) <hostN>(<options>)...

Example :


Now verify share with the following command

#exportfs -avr

Client side configuration

First of all install nfs-utils on client machine

# yum install nfs-utils

Now, check the shared directory over the network

#showmount -e

Here this IP is server IP 

Now for temporary mounting use the command

#mount -t nfs -o sync

For Permanent mounting please make entry in /etc/fstab file /mnt/nfsshare    nfs     nosuid,rw,sync,hard,intr  0  0

Mounting using autofs

Autofs is a program that automatically mounts specified directories on an on-demand basis. It is based on a kernel module for high efficiency, and can manage both local directories and network shares. These automatic mount points are mounted only when they are accessed, and unmounted after a certain period of inactivity. This on-demand behavior saves bandwidth and results in better performance than static mounts managed by /etc/fstab. While autofs is a control script, automount is the command (daemon) that does the actual auto-mounting. For Auto mounting setup 

Step1: Install autofs package on client Machine

#yum install autofs

Step2: Now start and enable autofs service on Machine

#systemctl enable autofs 
#systemctl start autofs

Step3: Now Create Master map file under /etc/auto.master.d/share.autofs

#vi /etc/auto.master.d/share.autofs

In this file add following content

/mnt/nfsshare /etc/auto.nfs

/mnt/nfsshare Mount Point
/etc/auto.nfs  Mapping file

Now edit /etc/auto.nfs file and add following content and save this file

#vi /etc/auto.nfs
*  -rw,sync,fstype=nfs4

Now restart the server

#systemctl reboot


Next How to Setup SFTP User Account on Fedora
Table of Contents