• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Configure NFS Share on Ubuntu 18.04 & 16.04

Written by Rahul, Updated on November 22, 2018
NFS NFS, NFS Mount, NFS Server

Network File System (NFS) is a distributed file system protocol. which allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.

This article will help you to install and configure NFS on Ubuntu systems and export a directory and mount it on the client system.

Network Details:

We have running two Ubuntu 16.04 LTS Systems in same network 192.168.1.0/24, Below given IPs are configured on server and client, which we will use in this tutorial.

Server: 192.168.1.100
Client: 192.168.1.110

Step 1 – Install NFS Server on Ubuntu

In this step, we will describe you to what packages you need to install and how to install them. Also describes who to export and directory using NFS server.

Use the following command to install the required packages to configure the NFS server.

sudo apt-get install nfs-kernel-server portmap

Step 2 – Export Shares over NFS

Now you need to configure NFS to export directory. For this tutorial we are creating a new directory, you may use any existing directory also.

I need to export /home directory and a new /opt/share directory on my NFS server. /home already exists on my system. Now create a new directory using below command.

sudo mkdir /opt/share
sudo chown nobody:nogroup /opt/share

Now edit the nfs server exports configuration file in a text editor as following:

sudo vim /etc/exports

Add following settings:

/etc/exports
/home          192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)
/opt/share     192.168.1.110(rw,sync,no_subtree_check)

Here /home can be mounted from the system with any IP of 192.168.1.0/24 LAN network. But /opt/share can only be accessed from IP 192.168.1.110.

Then apply the new settings by running the following command. This will export all directories listed in /etc/exports file.

sudo exportfs -a

To confirm and view exported directory use following command and you will get output like below

sudo exportfs -v

[Samput Output]
/home           192.168.1.0/24(rw,wdelay,no_root_squash,no_subtree_check)
/opt/share  192.168.1.110(rw,wdelay,no_root_squash,no_subtree_check)

Step 3 – Mount Share on Client Machine

After completing set up on the server side, login to clients system where we need to configure NFS client and mount exported directory by NFS server.

Install following packages on NFS client system, which is required to mount the remote directory using NFS protocol.

sudo apt-get install nfs-common portmap

Now we need to create mount points for mounting remote nfs exported directories.

sudo mkdir /mnt/share
sudo mkdir /mnt/home

After creating mount point, mount remote NFS exported directory using following command.

sudo mount 192.168.1.100:/opt/share /mnt/share
sudo mount 192.168.1.100:/home /mnt/home

Check mounted file system using below commands. As per below output both NFS mounted directories are listed at end of the result.

sudo df -h

[Sample Output]
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda1                      20G  2.8G   16G  16% /
udev                          371M  4.0K  371M   1% /dev
tmpfs                         152M  812K  151M   1% /run
none                          5.0M     0  5.0M   0% /run/lock
none                          378M  8.0K  378M   1% /run/shm
/dev/sr0                       32M   32M     0 100% /media/CDROM
/dev/sr1                      702M  702M     0 100% /media/Ubuntu 12.04 LTS i386
192.168.1.100:/opt/share       20G  2.8G   16G  16% /mnt/share
192.168.1.100:/home            20G  2.8G   16G  16% /mnt/home

Step 4 – Setup Auto Mount

Append the following entries to /etc/fstab file to mount NFS directories automatically after system reboot. This will mount directories on startup.

/etc/fstab
...
192.168.1.100:/home       /mnt/home  nfs  auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
192.168.1.100:/opt/share  /mnt/share nfs  auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Step 5 – Unmount NFS Share

If you want to remove the mounted file system, You can simply unmount it using umount command. Also, you need to remove entries from /etc/fstab (if added)

sudo umount /mnt/share
sudo umount /mnt/home

Share it!
Share on Facebook
Share on Twitter
Share on Google+
Share on Reddit
Share on Tumblr
Rahul
Rahul
Connect on Facebook Connect on Twitter Connect on Google+

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

1 Comment

  1. Bob Reply to Bob
    June 5, 2018 at 11:53 pm

    nice and clear

Leave a Reply

Cancel reply

Popular Posts

  • How To Install Zabbix Agent on Debian 9/8
  • How to Install and Configure Squid Proxy on Debian 9
  • How To Install Wine 3 on Debian 9 (Stretch)
  • How to Remove “public/index.php” from URL in Laravel
  • How to Install Swift on Ubuntu 18.04 LTS
All rights reserved. © 2013-2018 TecAdmin.net. This site uses cookies. By using this website you agree our term and services