Tutorial

How To Set Up an NFS Mount on CentOS 6

Published on September 18, 2012
How To Set Up an NFS Mount on CentOS 6
Not using CentOS 6?Choose a different version or distribution.
CentOS 6

Status: Deprecated

This article covers a version of CentOS that is no longer supported. If you are currently operating a server running CentOS 6, we highly recommend upgrading or migrating to a supported version of CentOS.

Reason: CentOS 6 reached end of life (EOL) on November 30th, 2020 and no longer receives security patches or updates. For this reason, this guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other CentOS releases. If available, we strongly recommend using a guide written for the version of CentOS you are using.

About NFS (Network File System) Mounts

NFS mounts work to share a directory between several servers. This has the advantage of saving disk space, as the home directory is only kept on one server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

Setup

An NFS mount is set up between at least two servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.

This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:

Master: 12.34.56.789

Client: 12.33.44.555

The system should be set up as root. You can access the root user by typing

sudo su

Setting Up the NFS Server

Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
yum install nfs-utils nfs-utils-lib
Subsequently, run several startup scripts for the NFS server:
chkconfig nfs on 
service rpcbind start
service nfs start

Step Two—Export the Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.

Suppose we wanted to share the directory, /home.

We need to export the directory:

vi /etc/exports

Add the following lines to the bottom of the file, sharing the directory with the client:

/home           12.33.44.555(rw,sync,no_root_squash,no_subtree_check)

These settings accomplish several tasks:

  • rw: This option allows the client server to both read and write within the shared directory
  • sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, 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.
  • no_root_squash: This phrase allows root to connect to the designated directory

Once you have entered in the settings for each directory, run the following command to export them:

exportfs -a

Setting Up the NFS Client

Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.

yum install nfs-utils nfs-utils-lib

Step Two—Mount the Directories

Once the programs have been downloaded to the the client server, create the directory that will contain the NFS shared files

mkdir -p /mnt/nfs/home

Then go ahead and mount it

mount 12.34.56.789:/home /mnt/nfs/home

You can use the df -h command to check that the directory has been mounted. You will see it last on the list.

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda               20G  783M   18G   5% /
12.34.56.789:/home       20G  785M   18G   5% /mnt/nfs/home

Additionally, use the mount command to see the entire list of mounted file systems.

mount

Your list should look something like this:

/dev/sda on / type ext4 (rw,errors=remount-ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
12.34.56.789:/home on /mnt/nfs/home type nfs (rw,noatime,nolock,bg,nfsvers=2,intr,tcp,actimeo=1800,addr=12.34.56.789)

Testing the NFS Mount

Once you have successfully mounted your NFS directory, you can test that it works by creating a file on the Client and checking its availability on the Server.

Create a file in the directory to try it out:

touch /mnt/nfs/home/example

You should then be able to find the files on the Server in the /home.

ls /home

You can ensure that the mount is always active by adding the directory to the fstab file on the client. This will ensure that the mount starts up after the server reboots.

vi /etc/fstab
12.34.56.789:/home  /mnt/nfs/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

You can learn more about the fstab options by typing in:

man nfs

After any subsequent server reboots, you can use a single command to mount directories specified in the fstab file:

mount -a

You can check the mounted directories with the two earlier commands:

df -h
mount

Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:

cd
sudo umount /directory name

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

df -h

You should find your selected mounted directory gone.

By Etel Sverdlov

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

great, concise tutorial. However, CentOS’s IP tables can be, in my experience, very picky about NFS & need tuning (& that’s beyond the scope of this comment ;-).

Also, CentOS assigns a uid & guid of 500 whereas Ubuntu (& others) assigns it as 1000 so you have to make sure that the uid & guid is set to nobody as in anonuid=65534,anongid=65534 for nfs shares between different distros.

These are very basic pointers & should be treated as such but they may help if anybody encounters any problems, I hope…

Etel Sverdlov
DigitalOcean Employee
DigitalOcean Employee badge
September 18, 2012

Thanks for the comment! I really could not have said it better myself :)

One of my favorite article in here. Nfs working perfectly on the digitalocean, Thanks.

Great article… But what’s with the IP’s way out of the range? .789 & .555? Made me take a second look at it when I was looking at your /etc/exports. I hadn’t read what you assigned to the client server so I had to go back up & figure out what those numbers were referring too because it looked like an IP but .555 isn’t a real IP address.

@keith: perhaps they are ipv5 addresses.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
July 14, 2013

@keithtshannon: These are not real IP addresses, they’re there just for the sake of making the article easier to follow :]

Hi Sir, I have one external HDD, i format it with ntfs filesystem by installing fuse-ntfs-3g*.rpm package and fuse module. I have mount it in Cento OS 5.5 by #mount -t ntfs-3g /mnt -o force. But the when i want to configure nfs for this mount_point say /mnt in Cento OS 5.5 like #vim /etc/exports /mnt *(rw,sync,no_root_squash) :wq 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… Faruk Assam, India

i have a question… i am working with 3 virtual servers, mi first question is: i can use NFS between virtual hard disks ? i am using CentOS 6.5 and i install NFS with the command : #yum install nfs-utils nfs-utils-lib but when i starting the service chkconfig nfs on (it is ok ). service rpcbind start (here gives me an error, “rpcbind: unrecognized service”). service nfs start ([root@server1 ~]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp). [FAILED] Starting NFS mountd: [FAILED] Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused) rpc.nfsd: unable to set any sockets for nfsd [FAILED] ).

i still can’t success run the service, someone could help me or guide mi with my problem ? escuse me for my english, i am still learning. thank you for take the time to read my question .

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
May 1, 2014

@jc.gonzalez.r92: Do you have rpcbind installed?

<pre> yum install rpcbind </pre>

@Andrew SB hi thanks for your answer, that’s what I’m trying but does not work with that command. I’ll be down the code to compile and install.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.