Installation and Configuration of NFS Server on ubuntu/centos

NFS installation and configuration

NFS Server

NFS means Network File System which is using to share one system data or directory over the remote network on multiple systems and you will able to access shared directory on your local system as local files or directory.

Why we need NFS Server?

  • NFS allows local access to remote files.
  • with help of NFS, we can create centralized storage which will be accessible from multiple systems.
  • No need to refresh filesystem to get new files.
  • Not necessary that both the client and host machine has a same operating system.

Installation & Configurations steps :

Before we start the configuration of NFS server, we need to install some components of NFS on host and client system.

On ubuntu/Debian system we will be going to install NFS package with the help of apt-get command but before installing NFS package do remember to update your apt-get repo with apt-get update command.

so use below commands to update repo and install NFS package.

Ubuntu/Debian :

  • apt-get update
  • apt-get install nfs-kernel-server

Centos/Redhat :

  • yum install nfs-utils nfs-utils-lib
  • yum install portmap

Note: In Centos/Redhat, Don’t use yum update command because it will directly update and installed latest packages on system.

To start/restart nfs service use below commands,

Ubuntu/debian :

  • /etc/init.d/nfs-kernel-server start|restart|status

Centos/Redhat :

  • /etc/init.d/nfs start|restart|status
  • /etc/init.d/portmap start

portmap service will help to map calls made from another system to correct RPC Service.

Important configuration files after installing packages :

Ubuntu/Debian :

  • /etc/idmapd.conf : This file is used for mapping UID and GID of the local user to the mounted NFS share but when you change uid and gid from nobody to another user it won’t reflect until you run “nfsidmap -c” command will help to clear kernel cache on the system.
  • /etc/exports : This is an important config file, we will define shared directories and files in this file at NFS server end.
  • /etc/fstab : When we want to mount our shared directory permanently then we need to add share directory details in fstab file otherwise on reboot your share directory will be unmounted.


Centos/Redhat :

  • /etc/exports : This is an important config file, we will be defined shared directories and files in this file at NFS server end.
  • /etc/fstab :  when we want to mount our shared directory permanently then we need to add share directory details in fstab file otherwise on reboot your share directory will be umnout.
  • /etc/sysconfig/nfs : configuration file of NFS to manage port no. of NFS if you want to run NFS on some other port no. we can change that port in this file.

For testing actual scenario, we need at the list to system one is HOST and other is CLIENT.

Below are the ips of my host and client machine.

NFS Server :  

NFS Client  : 

We have already installed nfs server package on host machine and now we are installing package called “nfs-common” on client machine [] which will provides nfs functionlity without having to include server components.

Ubuntu/Debian :

  • apt-get update
  • apt-get install nfs-common

Centos/Redhat :

Here we need to install same package which we previously installed on host machine.

Now we will be creating a directory on host machine which is shared with a client or you can also share already existing directory.

mkdir /sharenfsdir

After creating a directory, we need to make or add an entry in “/etc/exports” configuration file and restart the services to make our directory shared on the client system.

vim /etc/exports


In above example, we will be sharing directory /sharenfsdir with client system ip( and provided read and write privileges on a shared directory. you can also use HOSTNAME of client machine instead of IP.

To reflect changes from exports config file we need to run below command,

  • exportfs -a


  • Restart services on the host machine.

So here we will be completed server  or service installation steps.

Configure NFS share directory on Client machine :

Now, we are going to start configuring client machine to access shareable directory. 

First we are going to check available shared directory on server for that use below command,

showmount -e

Above command shows shared directory /sharenfsdir is available with server ip

To mount that shared directory on client machine we use below mount command,

mount -t nfs  /mnt/nfsshare  [use any path but before mounting on any dir create that directory on system if not available]

with the above help of command we mounted directory on client machine temporarily if you want to make it permanent then add below entry under “/etc/fstab” file.

vim /etc/fstab /mnt/nfsshare  nfs defaults 0 0

Test working of NFS setup :

Create a file under the shared directory on the client machine and checked it on the server it is created or not.

  • cd /mnt/nfsshare
  • touch nfstestfile.txt

now go on the server and checked under the /sharenfsdir you will found the file under the /sharenfsdir.

To remove NFS mount use below command,

  • umount /mnt/nfsshare


Some important commands for NFS :

  1. showmount -e : it will shows you available shared directory on server.
  2. showmount -d : List all the sub directories.
  3. exportfs -a : it will help to reflect  and listed the changes done under the /etc/exports
  4. exportfs -v : Display’s list of share files and options on server.
  5. exportfs -r : Reflect the changes after modifying /etc/exports


This is all about NFS. I hope you will understand this tutorial if you have any doubts or queries leave your comments and suggestions below in comment box.

Stay connected with for more exciting and interesting posts in future.

Thank you 🙂


Latest Comments
  1. Trust Me November 13, 2016
  2. devops online training February 20, 2017
  3. Cardiologist January 12, 2018

Leave a Reply

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