In this guide, I’ll take you through the installation of NFSv3 and NFSv4 Server on CentOS 7. The only prerequisite for this is that you should have installed CentOS 7 server and data directory to export to other servers via NFS.

Install and configure NFSv3 and NFSv4 on CentOS 7

Below are complete steps to Install and configure both NFSv3 and NFSv4 on a CentOS 7 server.

NFSv4 schema

Step 1: Install NFS server

Install the nfs-utils package on CentOS 7 using the following commands:

# yum -y install nfs-utils

Step 2:  Configure domain used for NFS ( Optional)

# vim /etc/idmapd.conf
Domain =

Step 3: Configure NFS exports

NFS exports are configured under the file /etc/exports. The /etc/exports file controls which file systems are exported to remote hosts and specifies options. It follows the following syntax rules:

  • Comments start with the hash mark (#).
  • Blank lines are ignored by default.
  • Each host’s options must be placed in parentheses directly after the host identifier, without any spaces separating the host and the first parenthesis.
  • Each exported file system should be on its own individual line.
  • A list of authorized hosts needs to be separated by space characters.
  • Long lines can be wrapped with a backslash (\).

An entry for an exported file system has the following structure:

export host(options)

Variables used are:

export –> The directory being exported
host –> The host or network to which the export is being shared
options –> The options to be used for host

For multiple hosts with different options, the syntax is:

export host1(options1) host2(options2) host3(options3)

NFS export default options are:

ro: The exported file system is read-only and remote hosts cannot make any changes to the files shared on the file system. To allow hosts to make both reads and writes, specify the rw option instead.

sync: Aith this option, NFS server does not reply to requests before changes made by previous requests are written to disk. To enable asynchronous writes instead, specify the option async.

root_squash: This prevents root users that connect remotely from having root privileges. Instead, the NFS server will assign them the user ID nfsnobody. This effectively “squashes” the power of the remote root user to the lowest local user, preventing possible unauthorized writes on the remote server. To disable root squashing, specify no_root_squash.

To squash every remote user (including root), use all_squash. To specify the user and group IDs that the NFS server should assign to remote users from a particular host, use the anonuid and anongid options, respectively, as in:

export host(anonuid=uid,anongid=gid)

The uid and gid are user ID number and group ID number, respectively.

wdelay: This reduces disk write overhead by delaying writing to the disk if it suspects another write request is imminent. This can be disabled using no_wdelay, when default sync is on.

subtree_check: This option enables subtree checking. It can be disabled using no_subtree_check.

An example of a configuration line is below:


Where /mnt/data is the exported directory, and is the network permitted to access it with read/write permissions and no root squashing. The network specified can be replaced with a single IP address or use * for global access.

Note that you have to explicitly override each default for every exported file system. For example, if the rw option is not specified, then the exported file system is shared as read-only.

For more information on exporting options, refer to man exportfs.

Step 4: Configure Firewall for NFS

The next step is to open ports required by NFS service on the firewall.

For NFSv4, use the command:

# firewall-cmd --add-service=nfs --permanent
# firewall-cmd --reload

For NFSv3, you’ll need to add extra ports by defining an xml file. This needs to be placed under /etc/firewalld/services/ directory.

cat  /etc/firewalld/services/nfs.xml
<?xml version="1.0" encoding="utf-8"?>
  <description>NFS service
  <port protocol="tcp" port="111"/>
  <port protocol="udp" port="111"/>
  <port protocol="tcp" port="662"/>
  <port protocol="udp" port="662"/>
  <port protocol="tcp" port="892"/>
  <port protocol="udp" port="892"/>
  <port protocol="tcp" port="2049"/>
  <port protocol="udp" port="2049"/>
  <port protocol="tcp" port="32803"/>
  <port protocol="udp" port="32803"/>
  <port protocol="tcp" port="38467"/>
  <port protocol="udp" port="38467"/>
  <port protocol="tcp" port="32769"/>
  <port protocol="udp" port="32769"/>

Then add service on the firewall.

# firewall-cmd --add-service=nfs --permanent
# firewall-cmd --reload

Step 5: Start and enable NFS service

Now that everything is configured, you should be ready to start the service.

# for i in rpcbind nfs-server; do
systemctl start $i
systemctl enable $i

When you start the nfs service, the /usr/sbin/exportfs command launches and reads this file, passes control to rpc.mountd (if NFSv3) for the actual mounting process, then to rpc.nfsd where the file systems are then available to remote users. It writes exported file systems to /var/lib/nfs/etab, you can view using:

# cat /var/lib/nfs/etab

Step 6: Discovering NFS exports

There are two ways to discover which file systems an NFS server exports. First, on any server that supports NFSv3, use the showmount command:
$ showmount -e server


$ showmount -e localhost
Export list for localhost:
/mnt/test *

For a server that supports NFSv4 only, mount / and check the contents.

# mount  serverip:/ /mnt/
# cd /mnt/
# ls

Step 7: Mount exported file system on a client

The client can be any operating system that supports NFSv3 or NFSv4. For Debian/Ubuntu, install the following packaged:

$ sudo apt-get install rpcbind nfs-common

For CentOS 7, install nfs-utils:

$ sudo yum -y install nfs-utils
$ sudo systemctl start rpcbind 
$ sudo systemctl enable rpcbind

To do the non-persistent mounting, you can use the mount command.

mount -t /data

To specify NFS version, use -o option

# mount -t nfs -o vers=4 /data
# mount -t nfs -o vers=3 /data

To make this persistent, you need to modify /etc/fstab file. A mounting for NFSv3 look like below on /etc/fstab  /data nfs defaults,vers=3 0 0

You can see the vers=3 option is used to specify that we want to mount NFSv3. You can as well specify other supported options like below: /data nfs vers=3,proto=tcp,hard,intr,rsize=32768,wsize=32768,noatime 0 0

Create a mount point and mount it.

# mkdir /data
# mount -a
# df -hT | grep /data nfs 200G 175G 26G 88% /data


Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here