How to Setup NFS Server (Network File System) On Redhat/Centos/Fedora

In this article, we are going to learn how to Setup NFS Server (Network File System) as well as on Client in Linux. NFS Stands for ( Network File System ) also known as Linux File Server is a Network service in Linux used to share the File System/Directory of the Server to Users/clients on the network like Map Drive in Windows Systems and the user can access and store data on Central Location but This can be Possible only between Linux to Linux Systems or between Linux to Unix (Such as Vmware, Solaris Operating Systems) Systems. We also can access the share drive in Windows System but through Samba. The Port Number of NFS is 2049.

This NFS Protocol was first introduced by Sun Microsystem in 1984. The versions of NFS have been released over time i.e. NFS, NFSv2, NFSv3, NFSv4.

Let’s take a Scenario like In an Organisation we have some data which suppose to be accessed by all users, in that case instead of go and copy the data in all users system manually, we can set up NFS Server and put the data on the exported Directory then Share the Directory to all users to access the data Centrally. Thin Client users also can use NFS to store their data centrally and their login Profiles can be stored in NFS shared drive as a thin client doesn’t have Hardisk.

NFS DAEMONS

NFS Server uses several daemons to make available the exported directory from server to client computers over TCP/IP network and performs so many other tasks such as mount and unmount the exported file system, disk quota management, map client requests to NFS daemons and So on. The daemons are listed below :

• rpc.nfsd
• rpc.mountd
• rpc.portmapper
• rpc.rquotad
• rpc.statd
• rpc.lockd

MY SCENARIO

NFS Server:-

Hostname – Computer1
IP Address :- 192.168.0.106
Operating System – Linux

NFS Client:-

Hostname – Computer2
IP Address – 192.168.0.105
Operating System – Linux

As per the above scenario, we have two Computers i.e. Computer1 & Computer2 out of which Computer1 is going to be configured as an NFS Server and Computer2 as an NFS Client and Both computers are in the same network where “Computer1 has IP Address 192.168.0.106” and “Computer2 has IP Address 192.168.0.105”

So let’s have look at steps of NFS Server Configuration and Client-Side configuration in Linux.

How to Setup NFS Server (Network File System) On RedhatCentosFedora
How to Setup NFS Server (Network File System) On RedhatCentosFedora

NFS Server Side Configuration :

Step: 1 Install Required Packages

We need to install below mentioned Packages to Configure NFS.

nfs-utils.xxx.xxx.rpm
nfs-utils-lib.xxx.xxx.rpm
portmap.xxx.xxx.rpm
system-config-nfs.xxx.xxx.rpm (For Graphical configuration of NFS)

Install the above Packages by below command.

As we can see above we have installed all the required packages for NFS, Now let’s go ahead and configure the NFS from Server Side.

Step:2 Configure NFS in “/etc/exports”

Here we are going to Create three Directories named “applications”, “common” and “backup“in “/” and create some files in all created directories, Follow the below steps.

   
   # mkdir /applications
   # touch /applications/doc{1,2,3,4,5}.txt
   # ls /applications/
   doc1.txt  doc2.txt  doc3.txt  doc4.txt  doc5.txt

   # mkdir /common
   # touch /common/data{1,2,3,4,5}.txt
   # ls /common/
   data1.txt  data2.txt  data3.txt  data4.txt  data5.txt

   # mkdir /backup
   # touch /backup/test{1,2,3,4,5}.txt
   # ls /backup/
   test1.txt  test2.txt  test3.txt  test4.txt  test5.txt

I have created three directories to export all of them in /etc/exports file so that I can explain at least three different examples. Now give Full access to all created directories by using chmod command as shown below.

   
   # chmod 777 /applications/ /common/ /backup/

   # Output:
   
   drwxrwxrwx   2 root root  4096 Dec 25 00:05 applications
   drwxrwxrwx   2 root root  4096 Dec 25 00:08 backup
   drwxrwxrwx   2 root root  4096 Dec 25 00:07 common

Now let’s configure the main configuration file i.e. “/etc/exports”.

By Default the “/etc/exports” file would be empty, Now here we will export our “/applications“, “/common” and “/backup” directories by edit the “/etc/exports” Configuration file, Follow the below Steps.

Format of an entry in the “/etc/exports” file shown below.

directory-pathname         host-designation(options)

Example: 1

Here I am going to export the Directory /common with Everyone (all Users/Networks) with Read/Write (i.e. rw) and Synchronize access (i.e. sync), Follow the below steps.

   
   # nano /etc/common

   /applications   *(rw,sync)

Note: Here “*” means we have allowed the “/common” directory with Everyone So that any can access the directory and can store their data in this.

Example: 2

To share the directory with a Particular user you have just mentioned the IP Address of that System, Here we have shared the /applications Directory with a single system with IP Address 192.168.0.10 with Read Only (i.e. ro), and Synchronize Permissions (i.e. sync).

   
   # nano /etc/applications

   /applications   192.168.0.10(ro,sync)

Example: 3

Below scenarios configured to share the directory with all Hosts that are come under network 192.168.0.0 with Netmask 255.255.255.0. with Read Only and Synchronize Permissions.

   
   # nano /etc/backup

   /applications   192.168.0.0/24(ro,sync)

NFS Basic Permission Options

ro – Allows only Read-Only Access
rw – Allows Read/Write Access
sync – Performs all write when Requested.
async – Performs all write when the server is busy.

Now save the Configuration File then run the below command to activate the Export List.

  
   # exportfs -rav
  exporting *:/applications

Where:

  • r – Re-Export all Directories
  • a – Export or unexport all Directories
  • v – When Exporting and Unexporting shows whats going on.

exportfs” command used to maintain a list of NFS  exported file systems.

Now Start the nfs and portmap service by using below command.

  
   # /etc/init.d/nfs start
   Starting NFS services:                                     [  OK  ]
   Starting NFS quotas:                                       [  OK  ]
   Starting NFS daemon:                                       [  OK  ]
   Starting NFS mountd:                                       [  OK  ]

   # /etc/init.d/portmap start
   Starting portmap:                                          [  OK  ]

Start all the services on startup by using below command.

   
   # chkconfig --level 35 nfs on
   # chkconfig --level 35 portmap on

Now we have Done all required configurations from Server end, Now It’s time to check from NFS Client Side i.e. on Computer2.

Step:3 Configure NFS from Client Side

So Let’s have a look at the steps to configure NFS Client.

Before mount the NFS Server share directories from client side let’s check which directories been shared from Server Side by using below command.

   
   # showmount -e 192.168.0.106
   Export list for 192.168.0.106:
   /applications *


Note: Mention the IP Address of the Server.

1. Mount NFS shares manually:-

NFS manually mounting the command format shown below.


mount -t <nfs-type> <host>:</remote/export> </local/directory>

So to mount the Exported NFS directory from client-side just created a directory and run the below command, Here I have created a directory /nfs to mount the shraed directory “applications“.

 
   # mount -t nfs 192.168.0.106:/applications/ /nfs/

Where:

<nfs-type>:  Version of NFS you are using For Example NFS, NFS2, NFS3, NFS4.
 <host>  :  IP Address of the NFS Server.
</remote/export> :  Exported Directory Path from Server.
</local/directory>:  Directory Path where you are going to mount the NFS exported directory.

After mounting the file system using the below command to refresh the mount table by using the command mount -a and then run the command df -h to check the mounted file systems.

  
   # mount -a   # To Refresh the Mount Table

   # df -h

   
   Filesystem            Size  Used Avail Use% Mounted on
   /dev/sda1              18G  3.1G   14G  19% /
   tmpfs                 252M     0  252M   0% /dev/shm
   192.168.0.106:/applications/
                          18G  3.1G   14G  19% /nfs

Replace the <host> with the remote host(IP Address of the NFS Server), </remote/export> with the remote directory being mounted, replace </local/directory> with the local directory where the remote file system is to be mounted.

Follow the below steps to mount the NFS share Permanently in /etc/fstab.

2. Mount NFS shares in “/etc/fstab”

To mount the NFS exported directory permanently we need to enter it in /etc/fstab file, So follow the below step to do the same.
Entry for /etc/fstab Pattern shown below.

<server>:</remote/export> </local/directory> nfs <options> 0 0

  
   192.168.0.106:/applications     /nfs            nfs     defaults        0 0

How to Setup NFS Server (Network File System) On Redhat/Centos/Fedora

Replace the <server> with the IP Address of the Server.

Replace the </remote/export> with the directory path exported by NFS Server.

Replace </local/directory> with the local directory where the remote file system is to be mounted.

Also Read – Step By Step Linux DHCP Server Configuration In Redhat/Centos/Fedora

Now for just create a File or Directory on the exported directory from the Server end and go and check from the client-side, you will find the File/Directory. That’s all, In this article, we have explained How to Setup NFS Server (Network File System) On Redhat/Centos/Fedora. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.