7 C
Texas
Mel K
LInux Guru and Technical Writer

Install NFS Server and Client in CentOS 7 and Redhat 7

NFS (Network File System) is the popular distributed filesystem protocol. It’s better for users to mount remote folders on their local servers. Here, we will explain step by step how to create NFS server and how to mount the shared directories from the NFS clients.

My test systems are CentOS 7.4 with the following info:

NFS Server = 192.168.178.31
NFS Client = 192.168.178.32

[root@osradar ~]# uname -a
Linux osradar 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@osradar ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root@osradar ~]#
- Advertisement -

I-Install NFS Utils

“nfs-utils” includes all the needed services to build your NFS server. Let’s install it with the following commands:

yum install nfs-utils

Installed:
 nfs-utils.x86_64 1:1.3.0-0.48.el7

Dependency Installed:
 gssproxy.x86_64 0:0.7.0-4.el7 keyutils.x86_64 0:1.5.8-3.el7 libbasicobjects.x86_64 0:0.1.1-27.el7
 libcollection.x86_64 0:0.6.2-27.el7 libevent.x86_64 0:2.0.21-4.el7 libini_config.x86_64 0:1.3.0-27.el7
 libnfsidmap.x86_64 0:0.25-17.el7 libpath_utils.x86_64 0:0.2.1-27.el7 libref_array.x86_64 0:0.1.5-27.el7
 libtirpc.x86_64 0:0.2.4-0.10.el7 libverto-libevent.x86_64 0:0.2.5-4.el7 quota.x86_64 1:4.01-14.el7
 quota-nls.noarch 1:4.01-14.el7 rpcbind.x86_64 0:0.2.0-42.el7 tcp_wrappers.x86_64 0:7.6-77.el7

Complete!
[root@osradar ~]#

Now, create the directory for NFS service to share:

mkdir /var/nfs_share

Change the permissions of the shared folder:

chmod -R 755 /var/nfs_share
chown nfsnobody:nfsnobody /var/nfs_share

Let’s enable and start the services to make “nfs_share” accessible later and make them bootable on the next reboot.

systemctl enable rpcbind
 systemctl enable nfs-server
 systemctl enable nfs-lock
 systemctl enable nfs-idmap
 systemctl start rpcbind
 systemctl start nfs-server
 systemctl start nfs-lock
 systemctl start nfs-idmap

We will configure NFS directory over the network with the next step:

vi /etc/exports

and add

/var/nfs_share 192.168.178.32(rw,sync,no_root_squash,no_all_squash)

192.168.178.32 is the IP of NFS client machine. If you wish to all local network, use 192.168.178.0/24  or  “*” to allow connection from everywhere.

Restart the NFS service:

systemctl restart nfs-server

Here, add the rules below to allow the connection through the NFS service:

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

Before installing NFS clients, you need to share the folder.

[root@osradar ~]# exportfs
/var/nfs_share 192.168.178.32

II-Install  NFS Client

Run the same command to install all the needed NFS packages.

yum install nfs-utils

Create the NFS directory mount points:

mkdir -p /mnt/var/nfs_share

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

[root@localhost~]# mount -t nfs 192.168.178.31:/var/nfs_share /mnt/var/nfs_share/
[root@localhost~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.2G 15G 8% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 153M 862M 15% /boot
tmpfs 100M 0 100M 0% /run/user/0
192.168.178.31:/var/nfs_share 17G 5.3G 11G 33% /mnt/var/nfs_share
[root@localhost ~]#

We are connected. Now, you have the reading and writing access to the remote folder.

To mount this folder automatically on every boot, please add this line to “/etc/fstab”

192.168.178.31:/var/nfs_share /mnt/var/nfs_share nfs defaults 0 0

Enjoy! Please come back to us if you have any comment, question or suggestion.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article