UbuntuUbuntu Based

How To Install NFS Server on Ubuntu 24.04 LTS

Install NFS Server on Ubuntu 24.04

Network File System (NFS) is a powerful distributed file system protocol that allows you to share directories and files with multiple clients over a network. It’s an essential tool for system administrators and developers working in Linux environments, particularly when managing storage across different machines. In this comprehensive guide, we’ll walk you through the process of installing and configuring an NFS server on Ubuntu 24.04, the latest long-term support release of the popular Linux distribution.

Introduction

NFS has been a staple in Unix-like operating systems for decades, providing a reliable and efficient way to access remote filesystems as if they were local. Its popularity stems from its simplicity, performance, and ability to centralize data storage while allowing multiple clients to access shared resources simultaneously.

By setting up an NFS server on Ubuntu 24.04, you can:

  • Centralize file storage and management
  • Share resources across multiple machines
  • Implement efficient backup strategies
  • Optimize storage utilization in your network

This guide will take you through each step of the installation and configuration process, ensuring you have a fully functional NFS server by the end.

Prerequisites

Before we dive into the installation process, make sure you have the following:

  • A machine running Ubuntu 24.04 LTS (Focal Fossa)
  • Root or sudo privileges on the server
  • Basic familiarity with Linux command-line operations
  • A stable network connection
  • Sufficient storage space for shared directories

It’s also recommended to have a firewall configured on your system. If you haven’t set one up yet, you can follow Ubuntu’s official documentation on configuring the Uncomplicated Firewall (UFW).

Understanding NFS Components

To effectively set up and manage an NFS server, it’s crucial to understand its key components:

Server Components

  1. NFS Kernel Server: This is the core component that handles file sharing operations at the kernel level.
  2. RPC Services: Remote Procedure Call (RPC) services facilitate communication between the NFS server and clients.
  3. Export Configurations: These define which directories are shared and the access permissions for clients.

Client Components

  1. NFS Common Utilities: These are tools used by NFS clients to interact with NFS shares.
  2. Mount Utilities: These allow clients to mount and unmount NFS shares.
  3. Network Requirements: Clients need proper network configuration to access the NFS server.

Installation Process

Let’s begin the installation process for the NFS server on Ubuntu 24.04:

System Preparation

First, ensure your system is up-to-date:

sudo apt update
sudo apt upgrade -y

Next, install the NFS kernel server:

sudo apt install nfs-kernel-server -y

This command will install the NFS server along with its dependencies. Once the installation is complete, verify that the NFS server is running:

sudo systemctl status nfs-kernel-server

You should see output indicating that the service is active and running.

Basic Configuration

With the NFS server installed, let’s configure it to share directories:

Creating Share Directories

First, create a directory that you want to share:

sudo mkdir -p /var/nfs/shared

Set appropriate permissions for the shared directory:

sudo chown nobody:nogroup /var/nfs/shared
sudo chmod 777 /var/nfs/shared

Export Configuration

Now, we need to configure the NFS exports. Open the exports file with a text editor:

sudo nano /etc/exports

Add the following line to share the directory we created:

/var/nfs/shared *(rw,sync,no_subtree_check)

This line allows all clients (*) to access the shared directory with read-write permissions (rw), ensures changes are written to disk before replying (sync), and disables subtree checking for improved performance (no_subtree_check).

Save and close the file, then apply the new export configuration:

sudo exportfs -a

Security Configuration

Securing your NFS server is crucial to protect your data and network:

Firewall Setup

If you’re using UFW, allow NFS traffic through the firewall:

sudo ufw allow from any to any port nfs
sudo ufw reload

Access Control

You can restrict access to specific IP addresses or subnets by modifying the exports file. For example:

/var/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)

This limits access to clients on the 192.168.1.0/24 subnet.

Client Setup and Testing

To test your NFS server, you’ll need to set up a client machine:

Client Installation

On the client machine, install the NFS client utilities:

sudo apt update
sudo apt install nfs-common -y

Mounting NFS Shares

Create a mount point on the client:

sudo mkdir -p /mnt/nfs_client

Mount the NFS share:

sudo mount server_ip:/var/nfs/shared /mnt/nfs_client

Replace “server_ip” with your NFS server’s IP address.

Testing Connectivity

Verify the mount was successful:

df -h

You should see the NFS share listed in the output.

Advanced Configuration

For optimal performance, consider these advanced configurations:

Performance Tuning

Adjust the NFS server’s read and write buffer sizes:

echo "options sunrpc tcp_slot_table_entries=128" | sudo tee -a /etc/modprobe.d/sunrpc.conf
echo "options sunrpc tcp_max_slot_table_entries=128" | sudo tee -a /etc/modprobe.d/sunrpc.conf

These settings can significantly improve NFS performance, especially for large file transfers.

Troubleshooting Guide

If you encounter issues, try these troubleshooting steps:

  1. Check NFS server status:
sudo systemctl status nfs-kernel-server
  1. Verify exports:
showmount -e localhost
  1. Check client connectivity:
rpcinfo -p server_ip
  1. Review system logs:
sudo journalctl -u nfs-kernel-server

Congratulations! You have successfully installed NFS Server. Thanks for using this tutorial for installing the NFS Server on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official NFS website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button