Setup NFS share in Linux

Network File System (NFS) is the standard protocol used for sharing files/folder between Linux/Unix systems. This is helpful on production environments that requires a common folder on multiple servers. NFS shares provide quick and efficient file/folder sharing between systems. It’s easy to configure and setup. It’s not compatible on windows machines though- you can Samba protocol for this. This tutorial is done on CentOS but will also work on Ubuntu and other Linux OS.

NFS Server Setup:

Install packages for the server:
# yum install nfs-utils nfs-utils-lib

Make a folder to be share
# mkdir -p /home/share-folder

Make sure that the permissions is set to the user you want to connect. If the folder is owned by root, only root will be able to write, unless you change the permissions. Using default permissions as root:
# chown root:root /home/share-folder

Edit the export file for the NFS share. This file contains the list of directories to be exported or shared by the server.
# nano /etc/exports

On the /etc/exports file define the share folder path, define the allowed network to connect and define options of the share. This example will only share the folder to network 192.168.10.0/24
Ex:
/home/share-folder 192.168.10.0/24(rw,sync,no_subtree_check,no_root_squash)

After saving the exports file run the exportfs command to activate the exports file
# exportfs -a

Restart the nfs service.
# /etc/init.d/nfs restart

Now that the NFS share is exported on the server, we can configure the client to connect to the share.

NFS Client Setup:

On this section, you need to install packages for the client. This packages are needed to mount nfs shares
yum install nfs-utils nfs-utils-lib

Create a folder where you would like to mount the share, make sure the owner is the same as the owner of the nfs share
# mkdir /mnt/share-folder

Mount the nfs share using the following command, the IP address of the server and the NFS shared folder.
# mount -t nfs 192.168.10.5:/home/share-folder /mnt/share-folder

After the share is mounted, you can add it to the fstab to mount it during boot time.
# nano /etc/fstab

Add the following line to the fstab to mount the NFS share during boot-up.
192.168.7.167:/home/share-folder /mnt/share-folder nfs _netdev,rw,sync,no_subtree_check,no_root_squash 0 0


– masterkenneth

Leave a Reply

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