Network File System (NFS) Tutorial for CentOS 8

Network File System is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a computer network much like local storage is accessed. Wikipedia


Network File System (NFS) install in CentOS 8

Run the below commands for install the NFS server on the os.

dnf install -y nfs-utils

Start & Enable services

systemctl start nfs-server
systemctl enable nfs-server
systemctl status nfs-server

The configuration files for the NFS server are:

  • /etc/nfs.conf : Main configuration file for the NFS daemons and tools.

  • /etc/nfsmount.conf : An NFS mount configuration file.


Create directory and add in exports

  • We are going to create 2 directories called vm-disk for virtual machine disk, backup for daily backup of files, under the directory /resources

  • For create directories run the below commands

mkdir -p /resources/{vm-disk,backup}
  • Open the file /etc/exports using below command

vim /etc/exports
  • Add the below codes for allow client to access the directories authenticated by the IP block. go to file buttom and add

/resources/backup       192.168.1.0/24(rw,sync,no_root_squash)
/resources/vm-disk      192.168.1.0/24(rw,sync,no_root_squash)

Here

  • rw : allows both read and write access on the file system.

  • sync : tells the NFS server to write operations (writing information to the disk) when requested (applies by default).

  • all_squash : Maps all UIDs and GIDs from client requests to the anonymous user.

  • no_all_squash : Used to map all UIDs and GIDs from client requests to identical UIDs and GIDs on the NFS server.

  • root_squash : Maps requests from root user or UID/GID 0 from the client to the anonymous UID/GID.

    • Run the command for export the directories & then show them

  • -a : Its means export or unexport all directories.

  • -r : Its means reexport all directories, synchronizing /var/lib/nfs/etab with /etc/exports and files under /etc/exports.d

  • -v : enables verbose output.

  • -s : show the current status

exportfs -arv

exportfs  -s


Allow firewall to expose the NFS services

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


Setting Up NFS Client on Client CentOS

  • Install the NFS packages

dnf install -y nfs-utils
  • Run showmount -e 192.168.1.150 for see the NFS server directories.

  • Create directory for vm-disk using command mkdir -p /vm-disk

  • Mount or connect NFS server /resources/vm-disk disk to /vm-disk to run below command

mount -t nfs  192.168.1.150:/resources/vm-disk /vm-disk
  • go to the directory /vm-disk and create some file or directory it will create remote.