How to Install and Configure an NFS Server On CentOS 7

NFS is the abbreviation of Network File System. The biggest function is to allow different machines and different operating systems to share files with each other through the network.

The NFS server allows the client to mount the directory shared by the NFS server on the network to the local file system. In the local system, the remote host’s directory is like a disk partition.

NFS is generally used to store static data such as shared videos, pictures or files.


  • make sure you are logged in as a user with sudo privileges.
  • Make sure you can connect to the internet.
  •、CentOS 7、NFS server.
  •、CentOS 7、NFS client.

Install NFS Service

Step 01.Install NFS and PRC on CentOS

First, we need to install the NFS service on a CentOS 7 ( The two softwares that need to be installed during the installation are rpcbind and nfs-utils.

yum install -y rpc-bind nfs-utils rpcbind

Step 02. Start and set the NFS service to start automatically

Note that the service sequence is started. Start the RPC service first, and then start the NFS service. The startup command is as follows:

systemctl start rpcbind  #one
systemctl enable rpcbind #two
systemctl start nfs-server nfs-secure-server #three

then ,enable the nfs service to start automatically by typing the following command:

systemctl enable nfs-server nfs-secure-server

If the Firewall Firewall is enabled, you can use the following command to let the firewall release the nfs service.

firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd  --reload

Step 03.Configuring a shared directory

Create or use an existing directory on the server as a shared directory and configure the /etc/exports file to indicate the client IP and permissions that can be accessed. In this example, we create the shared directory /home/linuxhowto/webapp, edit the /etc/exports file with the vi editor, and add the corresponding content:


Parameter introduction:

Parameter description
ro read only
rw Read write
root_squash An anonymous user mapped to an NFS server when the NFS client is accessed as the root administrator
no_root_squash When the NFS client is accessed as the root administrator, it is mapped to the root administrator of the NFS server.
all_squash Anonymous user mapped to an NFS server regardless of the account access used by the NFS client
sync At the same time, the data is written to the memory and the hard disk to ensure no data loss.
async Prioritize data to be saved to memory and then to the hard disk; this is more efficient, but data may be lost

NFS client configuration

Step 01. View the directories allowed

Use the showmount command to view the directories allowed by the server and the IPs allowed to access by typing the following command:

showmount -e

The output should look somthing like this:

export list for

Usage of the showmount command:

Parameter description
-e Display the share list of the NFS server
-a The case of displaying the file resources mounted on the machine NFS resources
-v Display version

Step 02.Creates a directory and mounts the shared directory.

Create the directory /mnt/webapp as the mount directory for the shared directory On the client machine . Type the following command:

cd /mnt
mkdir webapp
mount -t nfs /mnt/webapp

Enable the system to automatically mount the directory, which can be mounted in the file /etc/fstab. Edit the file /etc/fstab and add the content:  /mnt/webapp    nfs    defaults 0 0

Step 03. Verify the mount

View the mount status with the df command:

df -h

The output will look somthing like this:

Filesystem      												Size  Used Avail Use% Mounted on
/dev/sda3       												1.1T  187G  827G  19% /
tmpfs            												32G   80K   32G   1% /dev/shm
/dev/sda1       												477M   40M  412M   9% /boot     17G  3.7G   14G  22% /mnt/webapp


In this tutorial, you have learned how to implement file directory sharing NFS between CentOS 7 servers. Of course, this tutorial also applies to the CentOS 6 series, and the client can be any Unix-like system. I hope this tutorial will help you. If you have better suggestions or other questions, please leave a comment below.

If you want to learn more about NFS content, please see the NFS documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *