How to Install and Configure NFS Server on CentOS 7

Installation and Configuration of NFS Server on CentOS Linux 7/Red Hat Linux 7/Oracle Linux 7

NFS stands for Network File System. In Linux the purpose of NFS server is to access files and directories from Linux server to Linux client machine, actually NFS is a distributed file system protocol that use for to share files and directories with in a network. NFS protocol is initially develop by Sun Microsystems in 1984.

Currently the major versions of NFS Server are using NFSv3, NFSv4 and NFSv4.1. NFS protocol provide a better file sharing, better security and better performance (caching). By the use of NFS server you can share files and directories to multiple client machines that reduces the storage cost of local disk.

In NFS server you can set the permissions on share folder for read and write (rw), read only (ro) and etc. In CentOS Linux 7/Red Hat Linux 7/ Oracle Linux 7 NFSv4 protocol is use that is a stateful distributed file system protocol.

Server Configuration:

To install NFS packages (rpcbind and nfs-utils) in NFS server type the below mention command. The attribute -y is use for to accept all the dependencies.

yum install rpcbind nfs-utils -y

install and configure nfs server on centos linux 7

The NFS packages (rpcbind and nfs-utils) has successfully installed. 

install and configure nfs server on centos linux 7

To start and enable the NFS packages services (rpcbind and nfs-utils), type the below mention commands.

systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

install and configure nfs server on centos linux 7

Create a folder that will be use to share a files and directories from NFS server to Linux client machines. Use command "mkdir" to create a folder. The attribute -p is use, when parent directory not available.

mkdir -p /nfs-server/backup

how to install and configure nfs server on centos linux 7

To set the permissions on directory "nfs-server" use command "chmod" with attribute -R that is use to set the permissions from parent directory to child directory.

chmod 777 -R /nfs-server

how to install and configure nfs server on centos linux 7

Use command "cd" to enter in the directory "/nfs-server/backup", after enter in the directory "/nfs-server/backup" create some files by use of command "touch"

cd /nfs-server/backup
touch owais abdul khan

how to install and configure nfs server on centos linux 7

By use of vi editor write the folder location in file "exports" that available in directory "/etc"

vi /etc/exports

how to install and configure nfs server on centos linux 7

Write the below mention folder/directory location with permissions in file "exports", that will use as a share folder/directory for Linux client machines.

/nfs-server/backup/ *(rw,sync)

how to install and configure nfs server on centos linux 7

Type the below mention command to check the NFS share folder export list.

showmount -e localhost
showmount -e

install and configure nfs server on centos linux 7

Add the below mention firewall rules to allow NFS shares from NFS server to client machines, after add the firewall rule must reload the firewall.

firewall-cmd --permanent --add-port=111/tcp
firewall-cmd --permanent --add-port=2049/tcp
firewall-cmd --permanent --add-port=20048/tcp
firewall-cmd --permanent --add-port=111/udp
firewall-cmd --permanent --add-port=2049/udp
firewall-cmd --permanent --add-port=20048/udp
firewall-cmd --reload

install and configure nfs server on centos linux 7

Client Configuration:

Install NFS packages (rpcbind and nfs-utils) in CentOS Linux client machine, type the below mention command. The attribute -y is use for to accept all the dependencies.

yum install rpcbind nfs-utils -y

install and configure nfs server on centos 7

The NFS packages (rpcbind and nfs-utils) on CentOS Linux client machine has successfully installed.

install and configure nfs server on centos 7

To start and enable the NFS packages services (rpcbind and nfs-utils) on CentOS Linux client machine, type the below mention commands.

systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

install and configure nfs server on centos 7

To check the NFS share folder export list on CentOS Linux client machine, type the below mention command.

showmount -e 192.168.10.226

Note: 192.168.10.226 is NFS server IP.

install and configure nfs server on centos 7

Create a folder that will be use to mount NFS server share folder. Use command "mkdir" to create a folder. The attribute -p is use, when parent directory not available.

mkdir -p /nfs-client/data/files

install and configure nfs server on centos linux 7

In above image you can see that the command "ls" is being use to list the content inside the directory.

To mount the NFS server share folder "/nfs-server/backup/" on CentOS Linux 7 client machine specific directory "/nfs-client/data/files/", type the below mention command.

mount -t nfs 192.168.10.226:/nfs-server/backup/ /nfs-client/data/files/

install and configure nfs server on rehat 7

To check NFS server share folder has successfully mount on CentOS Linux 7 client machine specific directory, type the below mention command.

df -hT

install and configure nfs server on rehat 7

To check CentOS Linux 7 client machine user have rights to edit the NFS server share folder files, first use command "cd" to enter in the directory "/nfs-client/data/files/" on CentOS Linux 7 client machine then edit file "abdul" by use of vi editor.

cd /nfs-client/data/files/
ls
vi abdul

install and configure nfs server on rehat 7

Here name "owais" has been edited in file "abdul".

install and configure nfs server on rehat 7

To check the file "abdul" on NFS server that the file has same text as we have written through client machine. Enter in the directory "/nfs-server/backup" by use of command "cd" then list the content inside the directory "/nfs-server/backup" by use of command "ls".

cd /nfs-server/backup
ls

install and configure nfs server on rehat 7

use vi editor to view the content inside the file or use the command "cat".

vi abdul

install and configure nfs server on rehat 7

For permanently mount NFS server share folder edit the file "/etc/fstab" by use of vi editor.

vi /etc/fstab

installation and configuration of nfs server on centos linux 7

Edit the below mention line on CentOS Linux 7 client machine for permanently mount NFS server share folder.

192.168.10.226:/nfs-server/backup/ /nfs-client/data/files/   nfs     rw,sync 0  0

installation and configuration of nfs server on centos linux 7

After save the file "/etc/fstab", reboot the machine by use of command "init 6" then use the command "df -hT" to verify the NFS server share folder is mount on CentOS Linux 7 client machine after reboot.

init 6
df -hT

installation and configuration of nfs server on centos linux 7

Thanks for read this Article

Comments