What is NFS and how to install it on Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


This is a rich topic which contains a lot of information that may interest you if you are into the storage area to be a system, storage or may be backup administrator.

There are variant types of file systems and our main topic today is about one of them and that is NFS.

Storage types

The three main types of storage are:




NAS (Network Attached Storage)

In a simple way, NAS is to share folders for others to store their data on instead of their local disks. You need to have a connectivity between the server and the clients for this to work and of course disks with free space on the server. NAS is a file level storage which means that you format the disks on the server side and share it with the formatted file system.

And here comes our NFS file system, it’s one of the file systems that you can format your NAS disks with, and this is what we want to do now, to use our Linux OS as a NFS server which actually means that we use it as a NAS server but with our disks formatted with NFS file system

NFS (Network File Sharing)

Is a protocol that allows you to share directories and files with other Linux clients over a network. Shared directories are typically created on a file server, running the NFS server component. Users add files to them, which are then shared with other users who have access to the folder.

An NFS file share is mounted on a client machine, making it available just like folders the user created locally. NFS is particularly useful when disk is out of space and you need to exchange public data between client computers.

NFS server side

First install NFS packages

# yum install nfs-utils rpcbind

Now enable the services at boot time

#  systemctl enable nfs-server
#  systemctl enable rpcbind

Start the services

#  systemctl start rpcbind
#  systemctl start nfs-server

Let’s create the shared directory for the clients to store or read their data

# mkdir /sharednfs

Set permissions so that any user on the client machine can access the folder (in the real world you need to consider if the folder needs more restrictive settings).

# sudo chown nobody:nogroup /sharednfs 
# sudo chmod 777 /sharednfs 

Grant access for NFS clients

To grant access to NFS clients, we’ll need to define an export file. The file is typically located at /etc/exports

Edit the /etc/exports file in a text editor, and add one of the following options

ro / rw :
a) ro : allow clients read only access to the share.
b) rw : allow clients read write access to the share.
sync / async :
a) sync : NFS server replies to request only after changes made by previous request are written to disk.
b) async : specifies that the server does not have to wait.
wdelay / no_wdelay
a) wdelay : NFS server delays committing write requests when it suspects another write request is imminent.
b) no_wdelay : use this option to disable to the delay. no_wdelay option can only be enabled if default sync option is enabled.
no_all_squash / all_squash :
a) no_all_squash : does not change the mapping of remote users.
b) all_squash : to squash all remote users including root.
root_squash / no_root_squash :
a) root_squash : prevent root users connected remotely from having root access. Effectively squashing remote root privileges.
b) no_root_squash : disable root squashing.

Example1 (single client):

# vi /etc/exports
/sharednfs {clientIP}(rw,sync,no_subtree_check)

Example2 (multiple clients):

# vi /etc/exports
/sharednfs {clientIP-1}(rw,sync,no_subtree_check)

Example3 (subnet):

# vi /etc/exports
/sharednfs {subnetIP}/{subnetMask}(rw,sync,no_subtree_check)

Make the NFS Share Available to Clients

Export the share to make the directory available to clients

# sudo exportfs -a 

-a : exports entries in /etc/exports but do not synchronize with /var/lib/nfs/etab
-i : ignore entries in /etc/exports and uses command line arguments
-u : un-export one or more directories
-o : specify client options on command line
-r : re-exports entries in /etc/exports and sync /var/lib/nfs/etab with /etc/exports

Then restart the service

# systemctl restart nfs-server

Firewall settings

By default all ports that not in use are disables in Linux, so we need to allow NFS ports in firewall configuration.

To do so, do the following

firewall-cmd --permanent --add-service mountd
firewall-cmd --permanent --add-service rpc-bind
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload

Client side

We need to install the package on the client machine as well

yum install -y nfs-utils

To check the shared folders on the specified server that are available for our client

showmount -e {serverIP}

It will show something like the following

Export list for {serverIP}:
/sharednfs {clientIP}

Mount the shared folders

Now, time to make the shared folders mounted on our client side

First, we need to make a point directory

mkdir /mnt/sharednfs

Time to mount

mount {serverIP}:/sharednfs /mnt/sharednfs

To verify, try to create a directory or a file on the mounted point

touch /mnt/sharednfs/test

To automount the NFS shares

Edit in fstab file

vi /etc/fstab

add this line

{serverIP}:/sharednfs /mnt/sharednfs    nfs     nosuid,rw,sync,hard,intr  0  0

To unmount the NFS shares

umount /mnt/sharednfs

Finally, don’t forget to add the firewall rules on the client side as well

firewall-cmd --permanent --add-service mountd
firewall-cmd --permanent --add-service rpc-bind
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload


NFS is a great protocol to centralize your data in one place or one shared folder instead of storing it locally on each device. This also gives you opportunity to come over the local limited space on your device.

With the proper connectivity and configuration, you’ll have perfect solution to store your data in one place.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"
Unix/Linux Guru and FOSS supporter


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook