Table of content

Network File System in Linux

Network File System(NFS) is a file system implemented by Sun Microsystems, Inc. It is a client/server system that lets the users access files across a network and work on them as if they are present in a local file directory.

For example, if we are using a computer connected to a second computer via NFS, we can access the files of the second computer as if they are located in a directory on the first computer. This is done by exporting(the process through which an NFS server gives remote clients access to its files) and mounting(the process by which the client maps NFS shared file system).

For NFS, we should have the client and server machine configuration.

Steps to configure the NFS server machine:-

  • Become a root user, with the command:
    su -​
  • To verify if the package nfs is installed in the system, with the command:
    rpm -qa | grep nfs​
  • If not installed, run the command to install:
    yum install nfs-utils​ libnfsidmap​
  • Enable and start the nfs services by running commands one by one:
    systemctl enable rpcbind
    systemctl enable nfs-server
    systemctl start rpcbind 
    systemctl start nfs-server
    systemctl start rpc-statd
    systemctl start nfs-idmapd​
  • To check the status of a service, for example: rpc-statd, run the command:
    systemctl status rpc-statd​
  • Create an nfs shared directory and assign permissions with the following steps:

Create a directory mypretzels at the / location with the commands:

cd /
mkdir mypretzels

Assign permissions to the directory with the command:

chmod a+rwx mypretzels/
  • Create files a, b, c, and kramer inside the mypretzels directory with the commands:
    cd mypretzels/
    touch a b c​
    touch kramer
  • Add some content to the kramer file, with the command:
    echo "These pretzels are making me thirsty" > kramer​
  • To get the contents of the mypretzels directory, run the command:
    ls -ltr​

linux-nfs

  • Edit the /etc/exports file with the command:
    vi /etc/exports​
  • In the insert mode, add the following lines:
    /mypretzels *(rw,sync,no_root_squash)​
  • Save and quit.
    :wq!​
  • Export the nfs filesystem with the command:
    exportfs -rv​
  • Check the IP address of the server machine, with the command:
    ifconfig​

linux-nfsipserver

The IP address of the server machine is 192.168.1.18.

Steps to configure NFS client machine:-

  • Become a root user, with the command:
    su -​
  • Check the IP address, with the command:
    ip addr​



The IP address of the client machine is 192.168.1.11

  • Install the nfs package with the command:
    yum install nfs-utils 
  • Install the rpcbind package with the command:
    yum install rpcbind -y​
  • Once installed, enable and start the rpcbind package with the command:
    systemctl start rpcbind​
  • Check the status of the rpcbind package with the command:
    systemctl status rpcbind​​
  • Ensure that the firewalld or iptable are stopped, with the command:
    ps –ef | egrep “firewall|iptable” ​
  • Show mount from the nfs server with the command:
    showmount -e 192.168.1.18​

    192.168.1.18 is the IP address of the server machine.

  • Create a mount point with the command:
    mkdir /mnt/kramer​
  • Mount the nfs filesystem with the command:
    mount 192.168.1.18:/mypretzels /mnt/kramer​
  • Verify the mounting system with the command:
    df -h​

linux-nfsmount

  • To verify if the contents of /mnt/kramer in the client machine matches with the contents of /mypretzels in the server machine run the commands one by one:
    cd /mnt/kramer
    ls -ltr​

linux-nfsfile

  • To unmount the mount point /mnt/kramer, run the command:
    umount /mnt/kramer​
About Author :

Myself Debomita Bhattacharjee, an IT employee with 6+ years of experience in Software industry. My area of interest is Automation testing and Front End Development.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions