Basics of Network File Sharing setup on linux

Introduction :

Network File Sharing (NFS) is a protocol which used to share the local hard disk Between the Linux machines over the network, that act as a local disk to the clent user.

Versions:

At present there are three versions of NFS

* NFSv2 – It is a older and is widely supported version

* NFSv3 – It supports safe asynchronous writes and a more robust error handling than NFSv2,it also supports 64-bit file sizes and offsets

* NFSv4 – It works through firewalls and on the Internet, no longer requires an rpcbind service, supports ACLs, and utilizes stateful operations

Port Number :

The Default Port Number of NFS is 2049 

Packages Needed:

The Packages needed for NFS are

* nfs-utils

 * portmap

* nfs4-acl-tools

Required Services:

To run the NFS the following dameon or services is used

* portmap (rpcbind for RHEL 6)

* nfslock

* nfs

Portmap :

portmap or RPC Program or otherwise called as rpcbind.NFS uses Remote Procedure Calls (RPC) to handle the requests between clients and servers.

nfslock :

It lock the files for remote and local nfs request .

nfs :

service nfs start the NFS server and the appropriate RPC processes to service requests for shared NFS file systems.

Configuring NFS on the Server :

Both the NFS server and NFS client need the NFS package installed and running on the machine. The server needs rpcbind, nfs, and nfslock operational, as well as a correctly configured /etc/exports file.The /etc/exports file is the main NFS configuration file, and it consists of two columns. The first column lists the sharing directories over the network. The second column has two parts. The first part is for mentioning the networks or DNS domains that can get access to the directory, and the second part is for NFS options in brackets.

 Example:

# vim /etc/exports

/home/example/share          192.168.1.2 (ro,sync)

:wq

Then Start the Required services

Configuring NFS on The Client :

NFS configuration on the client requires you to start the NFS application; create a directory on which to mount the NFS server’s directories that you exported via the /etc/exports file, and finally to mount the NFS server’s directory on your local directory, or mount point.

 /etc/fstab file

The /etc/fstab file lists all the partitions that need to be mounted automatically when the system boots. For this, we need to edit the /etc/fstab file if you need the NFS directory to be made permanently available to the users .

A valid /etc/fstab entry to mount an NFS export should contain the following information:

server:/remote-shaing-path/ /local-mounting-directory/ nfs options 0 0

Example:

# vim /etc/fstab

192.168.1.2:/home/example/sharing  /home/example2/remote-files  nfs  soft,nfsvers=2  0  0

:wq

Possible NFS Mount Options

bg   ==========>   Retry mounting in the background if mounting initially fails

fg   ==========>   Mount in the foreground

soft   ==========>   Use soft mounting

hard   ==========>   Use hard mounting

rsize=n   ==========>   The amount of data NFS will attempt to access per read operation. The default is dependent on the kernel. For NFS version 2, set it to 8192 to assure maximum throughput.

wsize=n   ==========>   The amount of data NFS will attempt to access per write operation. The default is dependent on the kernel. For NFS version 2, set it to 8192 to assure maximum throughput.

nfsvers=n   ==========>   The version of NFS the mount command should attempt to use

tcp   ==========>   Attempt to mount the filesystem using TCP packets: the default is UDP.

intr   ==========>   If the filesystem is hard mounted and the mount times out, allow for the process to be aborted using the usual methods such as CTRL-C and the kill command.

Temprovary Mount of NFS :

mount -t nfs [SERVER:sharing-path] [mounting-directory]

Example : #  mount -t nfs 192.168.1.2:/home/example/sharing /mnt/

( -t indicates the file system type )