Q. Iā€™m using CentOS 5 Linux 64 bit version. How do I share directory called /data2 to all other UNIX / Linux computers?

A. NFS (Network file system) is both a protocol and file system for accessing and sharing file systems across a computer network using UNIX and Linux. NFS v4 is used in modern Linux distributions. It offers performance improvements, mandates strong security, and introduces a stateful protocol etc.

How do I export a directory with NFS?

In order to export or share directory called /data2, you need to edit a file called /etc/exports. The file /etc/exports serves as the access control list for file systems which may be exported to NFS clients.:
# vi /etc/exports
Add config directive as follows:
/data2 *(rw,sync)

Each line contains an export point and a whitespace-separated list of clients allowed to mount the file system at that point. Each listed client may be immediately followed by a parenthesized, comma-separated list of export options for that client.


  • rw – Allow both read and write requests on /data2 NFS volume
  • sync – Reply to requests only after the changes have been committed to stable storage

Save and close the file. Restart the nfs service:
# /etc/init.d/nfs restart

NFS client configuration

Client computer need to mount file system using mount command or /etc/fstab file, enter:
# mkdir /mnt/nfs
# mount -t nfs4 nfsserver-name-or-ip:/data2 /mnt/nfs

Read the man page for more configuration options:
$ man exports

šŸ§ Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

šŸ§ 10 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Balaji Mar 20, 2012 @ 10:32

    Thanks, your steps were so simple and worked for me. The only change I had to do was run this: “mount -t nfs nfsserver-name-or-ip:/data2 /mnt/nfs” in the last step(“nfs” instead of “nfs4”). My Linux was 32-bit platform.

  • sandy Oct 7, 2012 @ 10:13

    Worked perfectly for me too! THANK YOU

  • techno May 2, 2013 @ 15:05

    The above information is actually for advanced admin who already knew what to do after..
    This is for we the beginners:
    1. make sure you have both the ipaddress and the hostname of the machine you want your directory to be shared with in /etc/hosts
    2. The file is /etc/exports is not created by default so you have to create it by vi into /etc/exports. when you vi, this file will be created; now press the letter i on you keyboard wile you are in vi to put you in insert mode..
    3. now enter the name of the directory or file that you want to share starting with a forward slash. tab once to enter the hostname or ipaddress of the machine whose name and ipaddress was entered in /etc/hosts followed by (rw, ro, sync)
    for instance, /share chilly(rw,sync). in this example, /share is the directory that i want to share. chilly is the hostname of the machine i want to share /share directory with which must be in /etc/hosts file.. rw is the permission which is granted to chilly.. sysn is to reply to requests only after the changes have been committed to stable storage. save and exit vi.. now share the exports file bu running this command /usr/sbin/exportfs -a

  • Maulik May 3, 2013 @ 11:10

    It works but vanishes when the box is restarted? Any way to put /etc/init.d/nfs start in startup script? New to linux.

  • mg75 Jun 2, 2013 @ 16:34

    any way to put /etc/init.d/nfs start in startup script?
    chkconfig nfs on

  • vichithra Jun 12, 2013 @ 7:18

    /etc/init.d/nfs start
    chkconfig –level 35 nfs on

  • Ashen Jul 4, 2013 @ 11:57

    Setup works. But got a problem. From the Client’s directory I want to get the permission to move files to another directory. How is it possible? with the current setup I cant perform it. Please help.

    Thanks in advance.

  • THEJUS V Dec 8, 2015 @ 13:39

    Thank you its very useful for exam thanks for google and also this website

  • Shahid Dec 11, 2015 @ 10:16

    I faced again 2 unrecognized service .how I resolve it

  • Mahi May 9, 2016 @ 15:06

    Simply superb, Worked perfectly for my environment

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum