Did You Know?
Got a tip? Let us know

HostGator Diwali Mega Offer 50% Flat Discount on all Hosting Plans - Grab it Now

How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.

Install NFS Server in Linux

Setup NFS Server and NFS Client in Linux

Benefits of NFS
  1. NFS allows local access to remote files.
  2. It uses standard client/server architecture for file sharing between all *nix based machines.
  3. With NFS it is not necessary that both machines run on the same OS.
  4. With the help of NFS we can configure centralized storage solutions.
  5. Users get their data irrespective of physical location.
  6. No manual refresh needed for new files.
  7. Newer version of NFS also supports acl, pseudo root mounts.
  8. Can be secured with Firewalls and Kerberos.
NFS Services

Its a System V-launched service. The NFS server package includes three facilities, included in the portmap and nfs-utils packages.

  1. portmap : It maps calls made from other machines to the correct RPC service (not required with NFSv4).
  2. nfs: It translates remote file sharing requests into requests on the local file system.
  3. rpc.mountd: This service is responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
  1. /etc/exports : Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  2. /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  3. /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other services are listening.

Setup and Configure NFS Mounts on Linux Server

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

  1. NFS Server: nfsserver.example.com with IP-
  2. NFS Client : nfsclient.example.com with IP-
Installing NFS Server and NFS Client

We need to install NFS packages on our NFS Server as well as on NFS Client machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package installers.

[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib
[root@nfsserver ~]# yum install portmap (not required with NFSv4)
[root@nfsserver ~]# apt-get install nfs-utils nfs-utils-lib

Now start the services on both machines.

[root@nfsserver ~]# /etc/init.d/portmap start
[root@nfsserver ~]# /etc/init.d/nfs start
[root@nfsserver ~]# chkconfig --level 35 portmap on
[root@nfsserver ~]# chkconfig --level 35 nfs on

After installing packages and starting services on both the machines, we need to configure both the machines for file sharing.

Setting Up the NFS Server

First we will be configuring the NFS server.

Configure Export directory

For sharing a directory with NFS, we need to make an entry in “/etc/exports” configuration file. Here I’ll be creating a new directory named “nfsshare” in “/” partition to share with client server, you can also share an already existing directory with NFS.

[root@nfsserver ~]# mkdir /nfsshare

Now we need to make an entry in “/etc/exports” and restart the services to make our directory shareable in the network.

[root@nfsserver ~]# vi /etc/exports


In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP “” with read and write (rw) privilege, you can also use hostname of the client in the place of IP in above example.

NFS Options

Some other options we can use in “/etc/exports” file for file sharing is as follows.

  1. ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  2. rw: This option allows the client server to both read and write access within the shared directory.
  3. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  4. no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  5. no_root_squash: This phrase allows root to connect to the designated directory.

For more options with “/etc/exports“, you are recommended to read the man pages for export.

Setting Up the NFS Client

After configuring the NFS server, we need to mount that shared directory or partition in the client server.

Mount Shared Directories on NFS Client

Now at the NFS client end, we need to mount that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.

[root@nfsclient ~]# showmount -e

Export list for

Above command shows that a directory named “nfsshare” is available at “” to share with your server.

Mount Shared NFS Directory

To mount that shared NFS directory we can use following mount command.

[root@nfsclient ~]# mount -t nfs /mnt/nfsshare

The above command will mount that shared directory in “/mnt/nfsshare” on the client server. You can verify it following command.

[root@nfsclient ~]# mount | grep nfs

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw) on /mnt type nfs (rw,addr=

The above mount command mounted the nfs shared directory on to nfs client temporarily, to mount an NFS directory permanently on your system across the reboots, we need to make an entry in “/etc/fstab“.

[root@nfsclient ~]# vi /etc/fstab

Add the following new line as shown below. /mnt  nfs defauls 0 0

Test the Working of NFS Setup

We can test our NFS server setup by creating a test file on the server end and check its availability at nfs client side or vice-versa.

At the nfsserver end

I have created a new text file named “nfstest.txt’ in that shared directory.

[root@nfsserver ~]# cat > /nfsshare/nfstest.txt

This is a test file to test the working of NFS server setup.
At the nfsclient end

Go to that shared directory in client server and you’ll find that shared file without any manual refresh or service restart.

[root@nfsclient]# ll /mnt/nfsshare
total 4
-rw-r--r-- 1 root root 61 Sep 21 21:44 nfstest.txt
root@nfsclient ~]# cat /mnt/nfsshare/nfstest.txt
This is a test file to test the working of NFS server setup.

Removing the NFS Mount

If you want to unmount that shared directory from your server after you are done with the file sharing, you can simply unmount that particular directory with “umount” command. See this example below.

root@nfsclient ~]# umount /mnt/nfsshare

You can see that the mounts were removed by then looking at the filesystem again.

[root@nfsclient ~]# df -h -F nfs

You’ll see that those shared directories are not available any more.

Important commands for NFS

Some more important commands for NFS.

  1. showmount -e : Shows the available shares on your local machine
  2. showmount -e <server-ip or hostname>: Lists the available shares at the remote server
  3. showmount -d : Lists all the sub directories
  4. exportfs -v : Displays a list of shares files and options on a server
  5. exportfs -a : Exports all shares listed in /etc/exports, or given name
  6. exportfs -u : Unexports all shares listed in /etc/exports, or given name
  7. exportfs -r : Refresh the server’s list after modifying /etc/exports

This is it with NFS mounts for now, this was just a start, I’ll come up with more option and features of NFS in our future articles. Till then, Stay connected with Tecmint.com for more exciting and interesting tutorials in future. Do leave your comments and suggestions below in the comment box.

I am a linux server admin and love to play with Linux and all other distributions of it. I am working as System Engineer with a Web Hosting Company.

Linux Services & Free WordPress Setup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties and want us to help you out. We offer wide range of Linux and Web Hosting Solutions at fair minimum rates. Please submit your orders by Clicking Here.

« Previous Post

Next Post »

35 Responses

  1. Martín says:

    Great tutorial, realy helps!

  2. drstu says:

    While it’s easy to create an /etc/exports file (linear for N machines), it is a real annoyance to create /etc/fstab entries and mount points (quadratic for N machines). Why doesn’t anyone ever talk about using autofs for this, so that stuff just gets automounted in /net/machine/whatever-got-exported ?

    Good article, but I don’t understand why nearly all articles overlook this.

  3. JFM says:

    No way I ever run something as insecure as NFS v3.

  4. Aravindan says:


    If any one happened to come across the error

    Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
    rpc.nfsd: unable to set any sockets for nfsd

    make sure that /etc/init.d/rpcbind is running

    if not please start the service and then restart the portmap

  5. dinesh says:

    sometimes nfs service not starts in that case you have to start nfslock and rpcbind services i come to know about this after reading this tutorial
    tomorrow; like your work admin

    sory for bad english :)

  6. Ruriko says:

    I am running Ubuntu 10.04 LTS. I have typed apt-get install nfs-utils nfs-utils-lib but it gave error: E: Couldn’t find package nfs-utils

    How to fix this?

  7. senthil says:

    very nice step by step explain

    thank you

  8. Julio says:

    Running in my Pc Fedora 19

    It’s already installed:
    #yum install nfs-utils nfs-utils-lib
    #yum install portmap

    I have a problem, when i try to start the service give me:
    [root@Pc4 init.d]# /etc/init.d/nfs start
    bash: /etc/init.d/nfs: No such file or directory

    What happen?

  9. Shyam says:


    Really great post i was struggling with NFS on RHEL6 from last three days, and only two tutorials helped me out one is this and other is
    Configure NFS on RHEL 6
    From your tutorials i was able to setup NFS. My system have IPTABLES & SELinux configured which blocked NFS client connection but with the help of second tutorial i was able to fix that.

  10. You misspelt “defaults” in the fstab section. It should read /mnt nfs defaults 0 0

  11. Mathivanan says:

    very help to me this tutorial.
    thanks somuch

  12. VPK says:

    For mounting…

    mount -t nfs /mnt/nfsshare
    mount -t nfs /mnt/nfsshare


    Which one is correct??

  13. Shahil says:

    If you are using NFS-version4 with ext4 file system then you can direct mount
    in /net

    For Example:-
    [root@linux ~]# cd /net/

    [root@linux]# ls
    nfsshare <———– your shared directory
    [root@linux]# pwd

    Here you can find you shared directory

  14. siva says:

    recently i try to mount my files using nfs .. i have 2 pcs which are packed with ubuntu 13.10.. from 1 system i used as sever ( and another one as
    i followed the procedure as u said above to install nfs on server
    for client i installed nfs-common package..
    my problem was i configure properly at the server side .. but the client side when i try to execute this line $showmount -e
    i got the following error report
    “rpc mount export: RPC: Timed out “”

    i’m not able to understand the problem from where it is.. either from server or from client side..
    tell me is there any other way to find out where the problem comes from??

    help me out how to resolve this issue!!!
    thanks in advance !!

  15. haffizuddin says:

    Hello Siva,

    Please check if you are able to telnet the port 111 from the client to host, if no then check the rcbind service on host.

    Haffizuddin S

  16. nahid says:

    Really helpful guide.Now remove confusion about nfs server and client.

  17. Azara says:

    Clear instructions! Very helpful! God Bless you!

  18. faruk abdullah says:

    Hello Siva,

    I have one external HDD, i format it in ntfs filesystem by installing fuse-ntfs-3g*.rpm package and fuse module. I have mount it in Cento OS by
    #mount -t ntfs-3g -o force.
    But the when i want to configure nfs like this.. [say mount_point : /mnt ]in Cento OS
    #vim /etc/exports
    /mnt *(rw,sync,no_root_squash)
    But when I am trying to mount from remote machine.
    [in remote machine]
    #mount -t nfs :/mnt
    Then one error message has come like this…

    #mount :/mnt failed reason given by server:permission denied.

    Please give me one solutions..

  19. Mina says:

    there is something wrong with me
    when i write the command to mount the server
    #mount -t nfs /mnt/nfsshare
    this error appear
    mount.nfs: access denied by server while mounting

  20. Nishu says:

    How to share the new mount point by NFS without restarting service at server side ?

    (Asked in interview)

  21. BillyG says:

    Hey :)
    Really great tutorial ! Thanks a lot !
    Everything looks fine, on the server, the services are launched OK, but I have a “permission denied” on the client side, even if the showmount -e gives the good informations…
    Would you have a suggestion ?
    Thx in advance ;)

    • santhosh says:

      check shared(exported) directory. there may be ro permission. change it rw. you will not get that error.
      Thank you.

  22. praveen says:

    hi ,

    in the above /etc/fstab screenshot mounting point is not mentioned correctly please check it .. :)

  23. Josue says:

    When wanting to mount the shared folder to the client, it hangs and does nothing, it could be?

  24. A HASSAN says:

    lovely, tutorial , after reading your tutorial ,I desire to make friendship with you .

  25. Sowmya says:

    Quick and easy one.. Superb Tarunika :)

  26. siva shankar says:

    Great !!!

    Nice tutorial….This doc cleared all of my queries. good to see these tutorials from tecmint.

  27. Qamrea alam says:

    Thanks team its done in Ist attempt.

  28. Chad says:

    Wonderful tutorial. Really learned a lot!

  29. TIS says:

    This is what you need to do if you are getting access denied

    1 – Update /etc/exports as this (remove IP add *)

    /nfsshare *(rw,fsid=0,insecure,no_subtree_check,async)

    2 – Set this values in configuration file /etc/sysconfig/nfs

    LOCKD_TCPPORT=32803 – This is uncommented so just add the value
    LOCKD_UDPPORT=32769 – This is uncommented so just add the value
    MOUNTD_PORT=892 – You need to add this line anwyhere
    RQUOTAD_PORT=875 – You need to add this line anwyhere
    STATD_PORT=662 – You need to add this line anwyhere
    STATD_OUTGOING_PORT=2020 – You need to add this line anwyhere

  30. If you want NFS service to start automatically as well as rpc bind this is what you need to do.

    Below is equivelent to “chkconfig servicename on”

    sudo systemctl enable nfs-server

    sudo systemctl enable rpcbind

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.