configure nfs share ubuntu

How to Configure NFS Share in Ubuntu

Network File System (NFS) is a distributed files system that allows users to share and access files over network as if they were located on local file system. In this case, there is an NFS server that hosts files & directories, and there are client systems that can access them. The folder to be shared is created on NFS server, and users add files & subfolders to this location. Then it is shared with users & systems who need to access the folder. In this article, we will look at how to configure NFS share in Ubuntu. We will specifically learn how to export directory to client system and mount it there.


How to Configure NFS Share in Ubuntu

Here are the steps to configure NFS share in Ubuntu. We will be using two Ubuntu systems – server at IP address 54.43.32.21 and client at IP address 54.43.32.22


1. Install NFS Server on Ubuntu

Open terminal on the server machine and run the following commands to install packages required for configuring NFS Server.

$ sudo apt-get install nfs-kernel-server portmap


2. Export Directory over NFS

You can use new folder as well as existing directories for exporting. We will use an existing folder /home/data and a new folder /home/project to export.

First we will create new directory and change its ownership.

$ sudo mkdir /home/project
$ sudo chown nobody:nogroup /home/project

Now open the NFS configuration file in a text editor.

$ sudo vi /etc/exports

Add the following two lines to it, one for new directory and one for the existing folder.

/home/data       54.43.32.0/24(rw,sync,no_root_squash,no_subtree_check)
/home/project    54.43.32.31(rw,sync,no_subtree_check)

As per the above configuration, the folder /home/data can be accessed from any system on 54.43.32.0/24 network while /home/project can be accessed only from 54.43.32.31.

Apply all changes with the above command.

$ sudo exportfs -a

You can verify the changes with the following command.

$ sudo exportfs -v


3. Mount Folder on Client system

Next, log into the client system and run the following command in order to install packages required to mount the exported folders on client system.

$ sudo apt-get install nfs-common portmap

Next, we create mount points to mount the remote exported folders.

$ sudo mkdir /mnt/project
$ sudo mkdir /mnt/data

Once you have created the mount points, run the following command to mount remote folders.

$ sudo mount 54.43.32.21:/home/data /mnt/data
$ sudo mount 54.43.32.21:/home/project /mnt/project

You can verify the mounted file system with the following command.

$ sudo df -h


4. Setup Auto Mount

Please note, the above mount will work only until next system reboot. In order to automatically mount these folders after system reboot, open /etc/fstab file in a text editor.

$ sudo vi /etc/fstab

Add the following lines.

54.43.32.21:/home/data     /mnt/project  nfs  auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
54.43.32.21:/home/project  /mnt/data nfs  auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0


5. Unmount NFS Share

If you want to unmount the mounted folders, you can do so by running the umount command on client system.

$ sudo umount /mnt/project
$ sudo umount /mnt/data

That’s it. In this article, we have learnt how to configure NFS share in Ubuntu. NFS is a useful file sharing system that allows you to create centralized file management. It also allows users to access their files from any client system. There is no need to manually refresh content since the files served during access are always the latest ones. You can customize the above steps as per your requirement.

Also read:

How to Download Directories & Subdirectories using Wget
How to Backup & Restore Odoo Database
How to Configure Odoo 13 with PyCharm
Install Odoo with Apache Reverse Proxy
How to Setup PostfixAdmin in Ubuntu

Leave a Reply

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