How to configure NFS file sharing
Network File System (NFS) is protocol that enables the users to mount remote directories on their server.
This tutorial explains the steps to configure NFS on a Centos/RHEL server.
Step1: Login to the server via ssh as root.
Step2: Install NFS server.
#yum install nfs-utils nfs-utils-lib
Step3: Start NFS service.
#systemctl start nfs-server.service
Step4: Configure NFS service to run in the startup.
#systemctl enable nfs-server.service
Step5: Create directory to share via NFS.
#mkdir /nfsshare
Step6: Update the configuration file '/etc/exports' with the details of directory to be shared.
#vi /etc/exports
Step7: Update the below contents to the configuration file.
/nfsshare ipaddress(rw,sync,no_root_squash)
Here we need to replace 'ipaddress' with the ipaddress or hostname of this server. Note that we can use many other options in configuration and are explained below.
ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
rw: This option allows the client server to both read and write access within the shared directory.
sync: Sync confirms requests to the shared directory only once the changes have been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
no_root_squash: This phrase allows root to connect to the designated directory.
Step8: Reload the configuration changes.
#exportfs -a
NFS server is ready now and we need to configure the client for this server.
Step9: Login to the client machine via ssh
Step10: Create the mount point for NFS.
#mkdir /mnt/nfsshare
Step11: We will get list of available shares by running the below command.
#showmount -e NFSSERVER
Here we need to replace "NFSSERVER" with the ipaddress of the NFS server
Step12: Mount the shared NFS directory
#mount -t nfs NFSSERVER:/nfsshare /mnt/nfsshare
Here we need to replace "NFSSERVER" with the ipaddress of the NFS server. This command will mount that shared directory in “/mnt/nfsshare” on the client server.
Step13: Open the file "/etc/fstab".
#vi /etc/fstab
Step14: Add the following contents to this file and save.
NFSSERVER:/nfsshare /mnt nfs defaults 0 0
Here we need to replace "NFSSERVER" with the ipaddress of the NFS server.
Step15: Reload the mount configuration.
#mount -a
That's all……