How to configure NFS file sharing

Network File System (NFS) is a popular distributed file-system protocol that enables users to mount remote directories on their server. The system lets you leverage storage space in a different location and write onto the same space from multiple servers in an effortless manner.

This tutorial explains the steps to configure NFS on a Centos server.

Step1: Login to the server via ssh

Step2: Install NFS server

#yum install nfs-utils nfs-utils-lib

Step3: Start NFS service

#/etc/init.d/nfs start

Step4: Configure NFS service to run in the startup

#chkconfig --level 35 nfs on

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

Save 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.

Step7: Restart NFS service

#/etc/init.d/nfs restart

NFS server is ready now and we need to configure the client for this server.

Step8: Login to the client machine via ssh

Step9: 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

Step10: 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.

Step11: Update the mount details in "/etc/fstab" to make it as permanent

#vi /etc/fstab

Save the below contents to this file.

NFSSERVER:/nfsshare /mnt nfs defaults 0 0

Here we need to replace "NFSSERVER" with the ipaddress of the NFS server.

That's all......

Also here by provding the list of some usefull NFS commands and their details.

showmount -e : Shows the available shares on your local machine
showmount -e <server-ip or hostname>: Lists the available shares at the remote server
showmount -d : Lists all the sub directories
exportfs -v : Displays a list of shares files and options on a server
exportfs -a : Exports all shares listed in /etc/exports, or given name
exportfs -u : Unexports all shares listed in /etc/exports, or given name
exportfs -r : Refresh the server’s list after modifying /etc/exports

Leave a Reply

Your email address will not be published. Required fields are marked *