Contact Info

Atlas Cloud LLC 600 Cleveland Street Suite 348 Clearwater, FL 33755 USA

support@dedirock.com

Client Area
Recommended Services
Supported Scripts
WordPress
Hubspot
Joomla
Drupal
Wix
Shopify
Magento
Typeo3

NFS (Network File System) allows users to mount remote directories on their servers, simplifying storage management across multiple clients. This tutorial provides a step-by-step guide on setting up an NFS mount on Ubuntu, including installing required software, configuring exports, and ensuring persistent mounts.

Introduction

NFS delivers a straightforward way to access remote systems over a network, allowing for efficient management of storage space. This guide outlines how to install NFS server and client software on Ubuntu, configure NFS exports, and create persistent mounts using /etc/fstab.

Prerequisites

To follow this tutorial, you will need:

  • Two Ubuntu servers, each with a non-root user that has sudo privileges and a configured firewall (UFW).
  • Knowledge of the private network IP addresses for both servers.

Step 1: Installing NFS Components

On the Host:Install the NFS server on the host machine:

sudo apt updatesudo apt install nfs-kernel-server

On the Client:Install the NFS client on the client machine:

sudo apt updatesudo apt install nfs-common

Step 2: Create Share Directories on the Host

Create a general-purpose NFS mount and a home directory share:

sudo mkdir -p /var/nfs/generalsudo chown nobody:nogroup /var/nfs/general

You can use an existing directory for the home share as follows:

sudo mkdir -p /home

Step 3: Configure NFS Exports on the Host Server

Modify the /etc/exports file to specify which directories to share:

/var/nfs/general    client_ip(rw,sync,no_subtree_check)/home               client_ip(rw,sync,no_root_squash,no_subtree_check)

Save and close the file, then restart the NFS server:

sudo systemctl restart nfs-kernel-server

Step 4: Adjust the Firewall on the Host

Check the firewall status:

sudo ufw status

Allow NFS traffic by opening port 2049 for the client:

sudo ufw allow from client_ip to any port nfs

Step 5: Create Mount Points and Mount Directories on the Client

Make directories for mounting the shares on the client:

sudo mkdir -p /nfs/generalsudo mkdir -p /nfs/home

Then, mount the shares using the host’s IP:

sudo mount host_ip:/var/nfs/general /nfs/generalsudo mount host_ip:/home /nfs/home

To verify that the shares are mounted, run:

df -h

Step 6: Test NFS Access

Test the NFS access by creating a test file in both shares:

sudo touch /nfs/general/general.testsudo touch /nfs/home/home.test

Check the ownership of the files using:

ls -l /nfs/general/general.testls -l /nfs/home/home.test

Step 7: Persistent NFS Mounts

To ensure that the mounts persist after a reboot, edit the /etc/fstab on the client:

host_ip:/var/nfs/general    /nfs/general   nfs defaults 0 0host_ip:/home               /nfs/home      nfs defaults 0 0

Step 8: Unmounting an NFS Share

If you want to unmount the directory, use:

sudo umount /nfs/homesudo umount /nfs/general

Edit /etc/fstab to ensure the mounts do not remount on the next startup.

Additional Considerations for Production Use

  1. Ensure NFS versions are compatible.
  2. Use performance optimization flags for better throughput.
  3. Secure your configuration by restricting access in /etc/exports and considering a VPN for remote connections.

Conclusion

This tutorial has detailed how to set up an NFS host and client, emphasizing key configurations and security practices. Remember to always consider the security implications of using NFS, particularly when dealing with sensitive data.

For further reading and advanced configurations, additional resources on NFS are widely available online.


Welcome to DediRock, your trusted partner in high-performance hosting solutions. At DediRock, we specialize in providing dedicated servers, VPS hosting, and cloud services tailored to meet the unique needs of businesses and individuals alike. Our mission is to deliver reliable, scalable, and secure hosting solutions that empower our clients to achieve their digital goals. With a commitment to exceptional customer support, cutting-edge technology, and robust infrastructure, DediRock stands out as a leader in the hosting industry. Join us and experience the difference that dedicated service and unwavering reliability can make for your online presence. Launch our website.

Share this Post
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x