All about Network File System (NFS)

As the name itself indicates it’s a file system on remote computer which can be accessed as a local filesystem on other computers in network.
Sharing file system in a network is a 3 step process
1. Start NFS service
To share/access files, NFS service should be running on the server which shares the file system. Download the script nfsServiceCheck, which check’s if NFS service is running and if it’s not running will start the service. This script caters to RHEL/SUSE/OEL and CentOS. For NFS service to be running properly, rpcbind service should be started first and then the NFS service, if it’s done in reverse order, file system cannot be exported. So make sure to start rpcbind service first and then the NFS service. Script attached in this post does take care of this while starting the NFS service. To use the script, create a shell script with the contents of file and execute the script (it does not accept any arguments) to start the rpcbind and NFS service. Script does not cater to stopping of service.

2. export the file system to other hosts in network
After the service is started, from the source server ( file system which needs to be accessed in other hosts ), filesystem should be exported.
If file system should continue to be exported even after system reboot, follow the below steps
#vi /etc/exports

Make the following entry in file
192.168.0.101(rw,sync,no_root_squash)
eg:
/nfsshare 192.168.0.101(rw,sync,no_root_squash)

Options:
ro: read only access to the shared files
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.
* can be specified in place of IP address to share to all hosts in network.
Do refer to man page for all options detail

execute the below command, to export the file system which was entered in /etc/exports file above
#exportfs

If file system need to be exported only for short duration and need not continued to be exported after system reboot, follow below steps
execute the following command
#exportfs -o ro,all_squash *:
eg: exportfs -o ro,all_squash *:/opt/omni/

3. Mount the file system in other hosts
After the filesystem is exported from source server, file system needs to be mounted on client system where it needs to be accessed.
#showmount -e 192.168.0.100
This command will display all the NFS shares exported on host 192.168.0.100

If file system should continued to be mounted even after system reboot, follow below steps
# vi /etc/fstab
192.168.0.100:/nfsshare /mnt nfs defaults 0 0

execute the below command, to mount the file system for which a entry was made in /etc/fstab file above
#mount -a

If file system needs to be mounted only for short duration and need not be remounted after system reboot, execute following command in shell
#mount 192.168.0.100:/nfsshare /mnt/

Now filesystem 192.168.0.100:/nfsshare is accessible on 192.168.0.101:/nfs/nfsshare

Unmount the share from client hosts
If entry was made in /etc/fstab file, remove the entry from file and then execute the command
#mount -a
If entry was not made in /etc/fstab file and file system was mounted using the mount command from shell, use the below command for unmounting
#umount /mnt/nfsshare

For unexporting the share from source system
If entry was made in /etc/exports file, remove the entry and execute the command
#exportfs
If file system was exported from shell without making an entry in /etc/exports file, use the below command to unexport the file system
#exportfs -u *:

Advertisements
This entry was posted in Unix and Unix Internals and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s