How To Setup an NFS Server and Client For File Sharing

NFS server and client setup

In this tutorial, I will explain how to set up an NFS server and client configurations for mounting an NFS share across systems in a network.[alert style=”e.g. white,

[alert style=”e.g. white, grey, red, yellow, green”] Note: This tutorial is based on Ubuntu 14.04 server. You can create a VM easily on the cloud or using vagrant. [/alert]

Setup an NFS server

In this setup, I have a ubuntu server with IP address 192.168.0.2.

1. Refresh the apt package index

sudo apt-get update

2. Install the NFS package.

sudo apt-get install nfs-kernel-server

3. Next, we need to create a directory that can be shared with other hosts in the network. I am going to create a folder in var directory.

sudo mkdir /var/nfs

4. Change the ownership of the NFS folder to “nobody” and “nogroup”.

sudo chown nobody:nogroup /var/nfs

The “nobody” is a user present in most of the Linux distros which belong to the “nogroup” which does not have any privileges on the system programs or files.

5. All the NFS configurations are set in the /etc/exports file. In which we can give specific permissions for a client to access the files in the share.

In this example, I have a client with IP 192.168.0.3. Open the exports file and make an entry as shown below.

/var/nfs    192.168.0.3(rw,sync,no_subtree_check)

6. NFS table holds all the exports of the shares. You can create one using the following command.

sudo exportfs -a

7. Now, let’s start the NFS service.

sudo service nfs-kernel-server start

That’s it! We have an NFS server up and running.

Setup NFS client Node

All the servers which need access to the NFS share need to install the NFS client packages.

1. Refresh the apt list and install the client package.

sudo apt-get update
sudo apt-get install nfs-common

2. Let’s create a folder that will be mounted to the remote NFS share.

sudo mkdir /mnt/nfs/

3. Now, mount the remote NFS directory with out local /mnt/nfs directory.

sudo mount 192.168.0.2:/var/nfs /mnt/nfs

4. Verify the mount using the following command. You will see NFS share listed in the file system.

df -h

The output looks like the following.

192.168.0.2:/var/nfs   40G  1.4G   37G   4% /mnt/nfs

5. Now you can test the share by creating a test file in /var/nfs folder of the NFS server and try to list that in your clients /mnt/nfs folder.

That’s it! You now have an NFS share server and client up and running. You can add more clients in the same way we set up our first client.

3 comments
  1. Hi, can you confirm that NFS is or is not the best for Linux/Linux networking, rather than Samba and others, what ever they may be??

  2. Is there something wrong here??

    In this setup, I have a ubuntu server with IP address 192.168.0.2.
    In this example, I have a client with IP 192.168.0.2. Open the exports file and make an entry as shown below.

    I take it that’s a type, and client should be 192.168.0.3??

    Any thoughts??
    Martin

Leave a Reply to Devopscube Cancel reply

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

You May Also Like