File Sharing with NFS on Linux

File Sharing with NFS on Linux

NFS(Network File System) is developed by Sun Microsystems for sharing files/folders between Unix systems. It allows to mount local file system on a network or a remote host to interact.
NFS works in client-server style. We need to install it on both sides to proceed for mounting. The below explains only configuring NFS on both sides.

Procedure to mount a file or directory from a Linux Machine :

Server Side Configuration:

  1. After installing, start the NFS service.
      • cd /etc/init.d
      • ./nfs start
    • Add an entry of the file or folder path to be shared in /etc/exports
      For Example :

        • /root/nfs.txt *(ro)

      * represents that the file or folder has been shared to NFS clients of all IP Addresses
      ro represents read only permission
      rw represents read and write permissions
      For Specific IP Address:

      • /root/nfs.txt
  2. Export the share.
      • sudo exportfs -a
  3. Restart the nfs server.
      • cd /etc/init.d
      • ./nfs restart
  4. Check if share is visible or not.
      • showmount -e

Client Side Configuration

  1. Install NFS client and start the service.
  2. Check if share is visible or not.
      • showmount -e (server_ip)
      • Example: showmount -e
  3. Create a directory where you want to mount the share. Mounts will be done in /mnt directory.
      • mkdir /mnt/nfstest
  4. Add an entry of the shared file path in /etc/fstab to prevent manual remounts after reboots.
      • Example: /mnt/nfstest nfs defaults 0 0
  5. Mount the NFS Share.
      • sudo mount -t nfs /mnt/nfstest

Leave a Reply