NFS (Network File System) allows files and directories to be shared and mounted between Linux servers over a network. In this guide, we will configure one Ubuntu server as an NFS server and mount the shared directory on another Ubuntu client server.

Introduction

NFS is commonly used to share directories between multiple servers. The NFS server provides a shared directory, while the client server mounts that directory and accesses it as a local filesystem.

Prerequisites

  • Two Ubuntu servers
  • Root or sudo access to both servers
  • Network connectivity between the NFS server and client server
  • NFS server IP address
  • Permission to modify /etc/exports and /etc/fstab

Implementation

Step 1: Install NFS Server

Log in to the server that will act as the NFS server and 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 server.

mkdir /nfsshare

Step 3: Change the Ownership

Change the ownership and group of the NFS share directory.

chown nobody:nogroup /nfsshare

Step 4: Configure the NFS Export

Open the /etc/exports file.

vi /etc/exports

Add the following entry:

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

Here:

  • 172.0.0.0/8 – Replace this with the IP address or IP range allowed to access the NFS share.
  • rw – Allows the client to read and write files.
  • sync – Forces NFS to write changes before sending data.
  • no_root_squash – Allows the root account on the client to access the exported filesystem with root privileges.
  • no_subtree_check – Disables subtree checking for the exported directory.

Step 5: Restart the NFS Service

Restart the NFS server service to apply the configuration.

systemctl restart nfs-kernel-server

Client-Side NFS Configuration

Step 6: Install NFS Client Package

Log in to the Ubuntu server that will act as the NFS client and install the required package.

apt-get install nfs-common

Step 7: Create the Mount Directory

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

mkdir /nfs

Step 8: Mount the NFS Share

Mount the NFS share using the NFS server IP address.

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

Replace xx.xx.xx.xx with the IP address of the NFS server.

Step 9: Configure Permanent Mounting

To automatically mount the NFS share after a system reboot, edit the /etc/fstab file.

vi /etc/fstab

Add the following entry:

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

Testing

Step 10: Verify the Mounted NFS Share

Use the following command to verify the mounted filesystem.

df -h

The /nfs mount point should appear in the output.

Step 11: Unmount the NFS Share

To manually unmount the NFS share, use:

umount /nfs

Step 12: Test the Permanent Mount Configuration

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

mount -a

If there are no errors, the NFS share should be mounted successfully.

Conclusion

NFS provides a simple way to share directories between Ubuntu servers over a network. By configuring one server as the NFS server and mounting the shared directory on a client server, files can be accessed from the client as a mounted filesystem. Adding the configuration to /etc/fstab also allows the NFS share to be mounted automatically after a system reboot.

Related Articles

Leave a Reply