Set up the NFS server and configure an NFS mount point on Ubuntu

Introduction

NFS (Network File System) allows files and directories on one server to be accessed remotely by another server over a network.

In this guide, we will configure an NFS server on Ubuntu and mount the shared NFS directory on a client Ubuntu server.

Prerequisites

Before starting, make sure:

  • Two Ubuntu servers are available.
  • One server will act as the NFS server.
  • The second server will act as the NFS client.
  • You have root or sudo access on both servers.
  • The client server can communicate with the NFS server over the network.

Implementation

Step 1: Install NFS Server

On the server that will provide the shared directory, install the NFS server package:

apt-get install nfs-kernel-server

Step 2: Create the NFS Share Directory

Create a directory that will be shared with the client:

mkdir /nfsshare

Change the ownership and group of the directory:

chown nobody:nogroup /nfsshare

Step 3: Configure NFS Exports

Open the /etc/exports file:

vi /etc/exports

Add the following line:

/nfsshare 172.0.0.0/8(rw,sync,no_root_squash,no_subtree_check)

The options used above are:

  • 172.0.0.0/8 – Specifies the client IP address or IP range allowed to access the NFS share.
  • rw – Allows the client to read and write files.
  • sync – Ensures changes are written before the request is completed.
  • no_root_squash – Allows the client-side root user to retain root privileges on the exported filesystem.
  • no_subtree_check – Disables subtree checking for the exported directory.

For better security, use the specific client IP address or a restricted network range instead of allowing a broad range.

Step 4: Restart the NFS Service

Restart the NFS service to apply the configuration:

systemctl restart nfs-kernel-server

Client Side NFS Configuration

Step 5: Install NFS Client Packages

On the Ubuntu client server, install nfs-common:

apt-get install nfs-common

Step 6: Create the Mount Point

Create a directory where the remote NFS share will be mounted:

mkdir /nfs

Step 7: Mount the NFS Share

Mount the NFS directory using the NFS server’s IP address:

mount -t nfs xx.xx.xx.xx:/nfsshare /nfs

Here, xx.xx.xx.xx represents the IP address of the NFS server.

Step 8: Configure Permanent NFS Mount

To automatically mount the NFS share after a system reboot, add an entry to /etc/fstab:

vi /etc/fstab

Add:

xx.xx.xx.xx:/       /nfs    nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

Testing

Verify the Mounted NFS Share

Run the following command:

df -h

The output should show the NFS filesystem mounted on /nfs.

Unmount the NFS Share

To unmount the NFS directory:

umount /nfs

Test the /etc/fstab Configuration

Since the NFS mount has been added to /etc/fstab, use the following command to test the configuration:

mount -a

This will attempt to mount the entries configured in /etc/fstab.

Conclusion

NFS provides a simple way to share files and directories between Linux servers. In this setup, one Ubuntu server acts as the NFS server and exports /nfsshare, while another Ubuntu server mounts that share under /nfs.

Configuring the share in /etc/fstab also allows the NFS mount to be restored automatically after a reboot.

FAQs

1. What is NFS used for?

NFS allows a client system to access files and directories stored on a remote Linux server as though they were part of its local filesystem.

2. Which package is required on the NFS server?

Install the following package on the NFS server:

apt-get install nfs-kernel-server

3. Which package is required on the NFS client?

Install:

apt-get install nfs-common

4. How can I make an NFS mount permanent?

Add the NFS share to /etc/fstab and run:

mount -a

5. How can I verify that the NFS share is mounted?

Use:

df -h

The mounted NFS filesystem should appear in the output.

How to Remove, Install Oracle Java JDK in Ubuntu 16.04

Learn how to manage Oracle Java JDK installation and removal on Ubuntu 16.04.

How to Install Node.js in Ubuntu 16.04

Learn how to install Node.js on an Ubuntu 16.04 server and configure the required packages.

Talk to our experts

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Writes about Web & Architecture at Pheonix Solutions.

Leave a Reply

Scroll to Top