Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Log in or Sign up

Search...

Tutorials Tags Forums Linux Commands Subscribe

 Tutorial search

Ad
Home NFS Server and Client Installation on CentOS 7

NFS Server and Client Installation on CentOS 7

This guide explains how to configure an NFS server on CentOS 7. On this page

Network File System (NFS) is a popular distributed filesystem protocol
that enables users to mount remote directories on their server. NFS lets 1 Preliminary Note
Ad
you leverage storage space in a different location and allows you to 2 At NFS server end
write onto the same space from multiple servers or clients in an 3 NFS client end
effortless manner. It, thus, works fairly well for directories that users 4 Permanent NFS mounting
need to access frequently. This tutorial explains the process of 5 Links
mounting an NFS share on a CentOS 7.6 server in simple and easy-to-
follow steps.
AD


Ad

1 Preliminary Note

I have fresh installed CentOS 7 server, on which I am going to install the NFS server. My CentOS server have hostname
server1.example.com and IP as 192.168.0.100
Ad


If you don't have a CentOS server installed yet, use this tutorial for the basic operating system installation. Additionally to the server, Ad

we need a CentOS 7 client machine, this can be either a server or desktop system. In my case, I will use a CentOS 7 desktop with
hostname  client1.example.com and IP  192.168.0.101 as a client. I will run all the commands in this tutorial as the root
user.

2 At NFS server end

As the first step, we will install these packages on the CentOS server with yum:


yum install nfs-utils

Now create the directory that will be shared by NFS: Sign up now!

mkdir /var/nfsshare

Change the permissions of the folder as follows:

 Tutorial Info
chmod -R 755 /var/nfsshare

chown nfsnobody:nfsnobody /var/nfsshare Author: Srijan Kishore


Tags: centos, linux, storage

We use /var/nfsshare as a shared folder, if we use another drive such as the /home directory, then the permission changes will  Share This Page
cause a massive permissions problem and ruin the whole hierarchy. So in case, we want to share the /home directory then
permissions must not be changed.

Next, we need to start the services and enable them to be started at boot time. 

40.2k Followers

systemctl enable rpcbind

systemctl enable nfs-server


 Popular Tutorials
systemctl enable nfs-lock

systemctl enable nfs-idmap


Securing Your Server With A Host-based Intrusion
systemctl start rpcbind
Detection System
systemctl start nfs-server

ISPConfig Perfect Multiserver setup on Ubuntu


systemctl start nfs-lock

20.04 and Debian 10


systemctl start nfs-idmap
The Perfect Server CentOS 7.6 with Apache, PHP
7.2, Postfix, Dovecot, Pure-FTPD, BIND and
Now we will share the NFS directory over the network a follows: ISPConfig 3.1

How to Install Graylog Centralized Log Management


System on Rocky Linux
nano /etc/exports
How to Install Neos CMS on Ubuntu 22.04

How to Install TIG Stack (Telegraf, InfluxDB, and


We will make two sharing points  /home and /var/nfsshare. Edit the exports file as follows: Grafana) on Ubuntu 22.04

How to Install Prestashop with Apache and Let's


Encrypt SSL on Debian 11

How to Install YOURLS self-hosted URL shortener
/var/nfsshare 192.168.0.101(rw,sync,no_root_squash,no_all_squash)
on CentOS 8
/home 192.168.0.101(rw,sync,no_root_squash,no_all_squash)

Managing A Headless VirtualBox Installation With


phpvirtualbox (Ubuntu 12.04)

Note 192.168.0.101 is the IP of the client machine, if you wish that any other client should access it you need to add it IP wise How to Install vTiger CRM Open Source Edition on
otherwise you can add "*" instead of IP for all IP access.
Debian 11
Ad

Condition is that it must be pingable at both ends.

Finally, start the NFS service:

systemctl restart nfs-server

Again we need to add the NFS service override in CentOS 7 firewall-cmd public zone service as:

firewall-cmd --permanent --zone=public --add-service=nfs

firewall-cmd --permanent --zone=public --add-service=mountd

firewall-cmd --permanent --zone=public --add-service=rpc-bind

firewall-cmd --reload

Note: If it will be not done, then it will give error for Connection Time Out at client side.

Now we are ready with the NFS server part.


Ad

3 NFS client end

In my case, I have a CentOS 7 desktop as client. Other CentOS versions will also work the same way. Install the nfs-utild package as
follows:

yum install nfs-utils

Now create the NFS directory mount points:

mkdir -p /mnt/nfs/home

mkdir -p /mnt/nfs/var/nfsshare

Next, we will mount the NFS shared home directory in the client machine as shown below:

mount -t nfs 192.168.0.100:/home /mnt/nfs/home/

It will mount /home of NFS server. Next we will mount the /var/nfsshare directory:

 mount -t nfs 192.168.0.100:/var/nfsshare /mnt/nfs/var/nfsshare/

Now we are connected with the NFS share, we will crosscheck it as follows:
df -kh

[root@client1 ~]# df -kh

Filesystem                    Size  Used Avail Use% Mounted on

/dev/mapper/centos-root        39G  1.1G   38G   3% /

devtmpfs                      488M     0  488M   0% /dev

tmpfs                         494M     0  494M   0% /dev/shm

tmpfs                         494M  6.7M  487M   2% /run

tmpfs                         494M     0  494M   0% /sys/fs/cgroup

/dev/mapper/centos-home        19G   33M   19G   1% /home

/dev/sda1                     497M  126M  372M  26% /boot

192.168.0.100:/var/nfsshare   39G  980M   38G   3% /mnt/nfs/var/nfsshare

192.168.0.100:/home           19G   33M   19G   1% /mnt/nfs/home


[root@client1 ~]#

So we are connected with the NFS share.

Now we will check the read/write permissions in the shared path. At client enter the command:

touch /mnt/nfs/var/nfsshare/test_nfs

So we successfully configured an NFS-share.

4 Permanent NFS mounting

We have to re-mount the NFS share at the client after every reboot. Here are the steps to mount it permanently by adding the NFS-
share in /etc/fstab file of client machine:

nano /etc/fstab

Add the entries like this:

[...]

192.168.0.100:/home /mnt/nfs/home nfs defaults 0 0

192.168.0.100:/var/nfsshare /mnt/nfs/var/nfsshare nfs defaults 0 0

Note 192.168.0.100 is the server NFS-share  IP address, it will vary in your case.

This will make the permanent mount of the NFS-share. Now you can reboot the machine and mount points will be permanent even
after the reboot.

Cheers, now we have a successfully configured NFS-server over CentOS 7 :)

5 Links
CentOS: http://www.centos.org/

About Srijan Kishore

Over 8 years of experience as a Linux System Engineer. Srijan is an RHCE (Red Hat Certified Engineer) with in-depth knowledge
in RHEL and CentOS, he also worked a lot with Debian and Ubuntu based systems, VM management and installing and
maintaining hosting servers.

view as pdf | print

Share this page:




Suggested articles

20 Comment(s)
Add comment
Name *
Email *

    

p

Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms

Comments

By: the centos guy Reply  

How to get owned, the easy way!

By: Dariusz Panasiuk Reply  

as of firewall, you will have to also include other services:


 
 
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --permanent --zone=public --add-service=mountd
firewall-cmd --permanent --zone=public --add-service=rpc-bind
firewall-cmd --reload

By: fuller Reply  

I have not tried but it looks promising!

By: Fuller Suppend Reply  

Now I have tried it and it is breeze!!! I am using CentOS 7.


Thanks a lot!!!!

By: hannes fuchs Reply  

have had problems with nfs-lock and nfs-idmap service enable:


solution: https://www.centos.org/forums/viewtopic.php?f=47&t=53896
systemctl enable rpc-statd.service systemctl enable nfs-idmapd.service

By: agqweghrwh Reply  

touch: cannot touch ‘/mnt/nfs/var/nfsshare/example’: Read-only file system

By: vannak Reply  

You need to change file permission to your client user and your client group. 
For example:
sudo chown client_user:client_group /var/nfsshare/

By: Charlie Reply  

My attempt at "mount -t nfs" didn't work, but "mount -t nfs4" did. Is this running over TCP? See below:
# mount -o ro cache.yum.com:/var/cache/yum/x86_64/7Server/ol7_latest/packages /cdrom
mount: mount to NFS server 'cache.yum.com' failed: System Error: No route to host.
devoi # mount -t nfs4 -o ro cache.yum.com:/var/cache/yum/x86_64/7Server/ol7_latest/packages /cdrom
# ls /cdrom
bash-4.2.46-21.0.1.el7_3.x86_64.rpm

By: Tonie Reply  

Thank you very much !!!

By: jos Reply  

thanks sreejan .It was a nice article on nfs

By: Stefan Reply  

Why are you starting the NFS Server on the NFS client? Is this a typo?
 
> systemctl enable nfs-server

By: ZIlmar Reply  

Works like a charm! Thank you for sharing.

By: BoBo Reply  

Hi! I use iptables firewall. How i must edit rules?

By: S.Germán Reply  

In the final section, section 4, it might be less error prone to pull the mount information out of /proc/mounts?
   grep nfsshare /proc/mounts 1>> /etc/fstab
It will save you typing and will reduce the chance of error in /etc/fstab. The only danger here though is making sure you type 1>> instead of just 1>

By: Mscomms Reply  

very useful thanks

By: greg Reply  

Ran into trouble executing 


systemctl enable rpcbind Failed to execute operation: No such file or directory
 

By: michael Reply  

now can you extrend this to integrate with freeIPA?


it would be great to see a tutorial where freeIPA sets up user /home automounts upon first login.

By: Emma Rogers Reply  

Very much useful for the beginner like me. Thank you so much!
By: Ray Radam Reply  

Thank you very much, I've been looking for solutions, I even go the iptables rabbit hole but found out it's not compatible with firewall so I really
appreciate this post. 

By: kirk london Reply  

the above worked

Home NFS Server and Client Installation on CentOS 7

Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice Top 

Howtoforge © projektfarm GmbH. Terms and Rules Privacy Policy

You might also like