====== About NFS ======
Network File System (NFS) is a distributed file system protocol that allows you to share remote directories over a network. With NFS, you can mount remote directories on your system and work with the files on the remote machine as if they were local files.
NFS protocol is not encrypted by default, and unlike Samba, it does not provide user authentication. Access to the server is restricted by the clients’ IP addresses or hostnames.
In this tutorial, you’ll go through the steps necessary to set up an NFSv4 Server on CentOS 8. We’ll also show you how to mount an NFS file system on the client.
====== Installing and enable NFS server ======
The “nfs-utils” package provides the NFS utilities and daemons for the NFS server. To install it run the following command:
yum install nfs-utils
systemctl enable nfs-server
systemctl enable nfs-server
NFS server configuration options are set in /etc/nfsmount.conf and /etc/nfs.conf files.
====== Exporting NFS Shares ======
There are two ways to configure exports on an NFS server.
* Manually editing the /etc/exports configuration file
* Using the exportfs utility on the command line
The /etc/exports file controls which file systems are exported to remote hosts and specifies options. It follows the following syntax rules:
* Blank lines are ignored.
* To add a comment, start a line with the hash mark (#).
* You can wrap long lines with a backslash (\).
* Each exported file system should be on its own individual line.
* Any lists of authorized hosts placed after an exported file system must be separated by space characters.
* Options for each of the hosts must be placed in parentheses directly after the host identifier, without any spaces separating the host and the first parenthesis.
We’ll create directory on /opt/apps that will be exported to NFS clients
we need to modify /etc/exports to configure NFS share. The structure is:
vi /etc/exports
/opt/apps 10.10.2.0/24(ro,no_root_squash)
The **no_root_squash** option disables root **squashing** – enables remote root user to have root privileges.
Once you’re done with the settings, use the exportfs utility to selectively export directories without restarting the NFS service or you can restart the service.
exportfs -rav
* r – Causes all directories listed in /etc/exports to be exported by constructing a new export list in /etc/lib/nfs/xtab
* a – All directories are exported or unexported, depending on what other options are passed to exportfs
* v – Verbose operation – Show what’s going on
or
systemctl restart nfs-server
SELinux boolean may need to be enabled.
setsebool -P nfs_export_all_rw 1
====== Mounting NFS shares on remote servers ======
Now that we’re done with NFS server configurations, the remaining part is mounting NFS shares on a client system.
===== Install NFS Client =====
yum -y install nfs-utils
===== Mouting NFS Share on the Client =====
We need to create a folder on clients where we are going to mount the remote NFS folder
mkdir /opt/apps
mount -t nfs -o nfsvers=4 10.10.2.242:/opt/apps /opt/apps
Verifying its all ok
df -hT | grep /opt/apps
To persist the changes across system reboots, Configure NFS mounting on /etc/fstab.
vi /etc/fstab
Add a line like with the following syntax to the end of file.
10.10.2.242:/opt/apps /opt/apps nfs defaults 0 0
Test your settings.
sudo umount /mnt
sudo mount -a
df -hT | grep /mnt