Step by Step – how to configure nfs server in linux

How to install & configure nfs server in linux      

     NFS – NETWORK FILE SUSTEM /SHARING

  • NFS stands for Network File System, and is a way to share files between machines as if they were on your hard drive. Linux can be both an NFS server and an NFS client, which means that it can export file systems to other systems, and mount file systems exported from other machines.
  • For example NFS sever could be a Linux system and Unix could be a client. But it can’t be a window system because window is not NFS compatible. The NFS server exports one or more directories to the client systems, and the client systems mount one or more of the shared directories to local directories called mount points. After the share is mounted, all l/o operations are written back to the server, and all clients notice the change as if it occurred on the local filesystem.
  • A manual refresh is not needed because the client accesses remote filesystem as if it were local. Because access is granted by IP address, a username and password are not required. However, there are security risks to consider because the NFS server knows nothing about the client system.

nfs server
                    A Typical view of the NFS Server structure in Linux/Unix system




 

       Profile for NFS Server:

  • Package                  :    nfs-utils
  • Daemons               :    nfsd, rpc.mountd, rpc.statd, rpc.lockd, rpc.rquotad
  • Script                      :    /etc/linit.d/nfs
  • Port number        :    2049
  • Configuration File :    /etc/exports
  • Other imp files      :   /etc/lib/nfs/etab,/var/lib/nfs/rmtab

  

 

Workflow of NFS and its Daemon

Nfs Server nfs server

 

 

 

Steps to configure NFS server:

Steps1: Install the NFS package using yum or rpm.

Steps2: create a dir or directory on partition and add some data in it

Steps3: Export the directory by editing /etc/exports file and using exportfs command

Steos4: Restart the services and make it permanent.

 

Step1: Install the NFS package.

  • Check whether the package is installed

            #rpm-q nfs-utils

If it not installed use following command to install it 

#yum install nfs-utils* -y

 

Step2: Create a directory or create a partition and mount it and make a mount point and add data to it.

  • Create a partition, format it and mount it, access the point and data to it

            #fdisk/dev/vda create a partition

     

  • Update the partition table and format it

            #partx -a/dev/vda

            #mkfs.ext4/dev/vda13

  • Create a directory and mount the partition over it and also make it permanent in/etc/fstab

  • Access the mount point and add some data in it

 

Step3: Export the directory by editing /etc/exports file and using exportfs command

  • Edit the /etc/exports file

    #vim /etc/exports

nfs server

/ktdir                         :  Name of the directory to be exported 

192.168.10.0/24     :  Range of network where directory can be mounted

To give permission to only one node, just give the IP ADDR

Of that node (ex: 192.168.10.93)

(rw, sync)                 :   Mount options

 

The Mount options which can be used

 

rw                            :  Sets read/write permissions

ro                             :  Sets read-only permission

sync                        :  Specifies that all changes must be written to disk before a

                                    Command completes

No_wdelay           :  Forces the writing of changes immediately (useful for logs if

                                   Something crashes)

Root_squash       :  Prevent root users

  

  • Now run the exportfs command to export the directory

 #exportfs -avr

-a   Exports or un-exports all directoriesOptions:

-r    Reexport all directories

-u   Unexports one or more directories

-v    Provides verbose output

 

Step4: Restart the services and make it permanent.

       #service nfs restart

 

Check the directories which is exported in/var/lib/nfs/etab and/var/lib/nfs/rmtab 

 

Note: stop the iptables services by using #service iptables stop and chkconfig iptables off.

Client side configuration for NFS Server mounting

 

Step1: Check and install the NFS package if not installed

Step2: Start the NFS services

Step3: Check which directory is exported for this machine using showmount      

            Command

Step4: Make a directory and mount the NFS dir over it.

Step5: Add some data to it and check the same is updated on server side.

 

Step1: Check and install the package for NFS Server

        #rpm –q nfs-utils

It is already installed, if it is not installed use yum install nfs-utils* -y

 

Step2: check and start the NFS services and make it permanent

        #service nfs start

        #chkconfig –list nfs

 

Step3: Check which directory is exported for this machine using showmount command

  • To check exported directories form server the syntax is

      #showmount –e <server ip address>

 

Step4: Make a directory and mount NFS over it.

        #mkdir /ktnfs

        #mount –t nfs 192.168.10.91:/ktdir/ktnfs

        

Step5: Add some data to it and check the same is updated on server side 

 

  • Note that it is showing permission error because on server side the directory does not have write permissions neither for group nor for others.
  • Log into server and add write permission to NFS directory

 

  • Now , Again move back to client machine and try uploading some files 

 

  • To make it permanent mount edit /etc/fstab file as follows

This is the step by step configuration of NFS server……Please Like, Comment & share…

 

One thought on “Step by Step – how to configure nfs server in linux

Leave a Reply

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