How To Share Directory Via NFS on RHEL 7

Network File System (NFS) is one of the most used technologies to share directories/folders from one server to another in UNIX-based systems. As it is a widely used technology in industries so every UNIX/Linux administrator should know how to set up NFS and share directories.

In today’s tutorial, we are going to tell you how to share directories through NFS from any RHEL 7 / CentOS 7 server to another Linux servers.

How To Share Directory Via Network File System (NFS) on RHEL 7

In this tutorial, we will use two Red hat Enterprise Linux 7 (RHEL 7) system, where one will work as a server and the other will work as a client where the shared directory will be mounted.

Steps to Share Directory through Network File System (NFS) on RHEL 7

NFS Server-Side Settings

1. First, you will have to install the NFS package on the server. Check if the package is already installed or not by the below command.

# rpm -qa |grep -i nfs

If NFS packages are not installed, then install them using your local YUM repository.

# yum install nfs-utils libnfsidmap

Once, packages are installed, you can again verify using the above command, it should look like the below output.

[root@server ~]# rpm -qa |grep -i nfs
libnfsidmap-0.25-12.el7.x86_64
nfs4-acl-tools-0.3.3-13.el7.x86_64
nfs-utils-1.3.0-0.21.e

2. Now, create a directory to be shared through NFS. For this tutorial, we will be creating a folder called “nfs” on root mount point and will give it 777 permission using the chmod command so that everyone can read, write and execute. It Will also set a sticky bit for its protection.

# mkdir /nfs
# chmod 1777 /nfs

3. Now, open the configuration file of NFS i.e. /etc/exports, and enter the details of the client’s server along with the permission which needs to be given.

[root@server ~]# vi /etc/exports
[root@server ~]# cat /etc/exports
/nfs	client11.example.com(rw,sync)

Here, we have used the most common options, like rw and sync. This will give share read-write permission to the client and real-time syncing.

Use the below commands to export the directory and check what is currently being exported by the NFS server.

# exportfs –r
# exportfs –v

4. Now start your NFS server, and enable it, so that it can withstand reboots. Use the below commands for it.

# systemctl start nfs-server.service
# systemctl enable nfs-server.service
# systemctl start rpcbind
# systemctl enable rpcbind

The Firewall also needs to be set properly for the network file system (NFS) to work properly. Use the below commands to add NFS service to firewall exceptions.

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

Below is an example of starting the NFS service, enabling it, and checking its status.

[root@server ~]# systemctl start nfs-server.service 
[root@server ~]# systemctl enable nfs-server.service 
ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/multi-user.target.wants/nfs-server.service'
[root@server ~]# systemctl status nfs-server.service 
nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled)
   Active: active (exited) since Sat 2016-05-28 16:45:44 IST; 1min 21s ago
 Main PID: 5394 (code=exited, status=0/SUCCESS)
[root@server ~]# 

Once you have done the above steps, you are good to proceed to the client setup for network file system (NFS) sharing.

NFS Client Settings

5. First of all, create a directory that will be mount point for the NFS share.

# mkdir /nfsshare

6. Now start rpcbind service and enable it.

# systemctl start rpcbind
# systemctl enable rpcbind

Note: Client server does not require NFS services to be running.

7. Now, mount the NFS share on your client-server with the mount command.

# mount –t nfs server:/nfs /nfsshare

For permanent mounting make an entry in the “/etc/fstab” file like below and test by rebooting the server.

# vi /etc/fstab
 server.example.com:/nfs	/nfsshare	nfs	defaults	0 0

This is how you can set up a network file system (NFS) server and share directories using it to the client machines.


This is a very basic setup with minimal options, we will be covering more NFS tutorials in detail in our next tutorial. You can expect tutorials on Kerberos enabled NFS sharing, troubleshooting NFS, sharing through NFS version 4, etc.

If you want to get more such tutorials then subscribe to our newsletter for free, like us on Facebook, follow us on Twitter and keep sharing our articles.

Buy me a coffeeBuy me a coffee

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.