NFS Mount on Ubuntu Made Easy: A Complete Walkthrough

NFS Mount on Ubuntu

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

NFS mount on Ubuntu is your answer to share files between Linux machines seamlessly. Whether you’re setting up a home network or managing enterprise servers.

NFS, or Network File System, is a way to share files over a network that lets you connect to directories on other servers. This means you can handle storage that’s not local and allow multiple computers to write to that space. NFS is a standard and efficient method to reach remote systems and is great for when you often need to access shared resources.

This article covers NFS mount on Ubuntu installation, configuration, troubleshooting, and best practices.

What is NFS? Why Use NFS on Ubuntu?

The Network File System (NFS) is a way to store files over a network. It’s a distributed file system that lets users access files and folders on other computers and use them just like they’re on their own machine.

For instance, users can run operating system commands to create, delete, read, write, and change properties of files and folders that are on remote systems.

The NFS software package comes with commands and services for NFS, Network Information Service (NIS), and more. Even though NFS and NIS are bundled together, they work independently and need to be set up and managed separately.

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Benefits of a distributed file system

  • Offers central management.
  • Makes it easy for clients to share data.
  • Ensures security, meaning you only need to secure the servers to keep the data safe.

Overview of Client/Server Architecture

It consists of both a server-side and a client-side file system.

  • To access files on the client-side file system, which pulls files from the server, a client program makes a system call.
  • No specific API is needed, and the process is transparent to a client application.
  • To respond to these system calls, the server-side file system runs commands.
  • The first successful distributed system, the Network File System (NFS), was created by Sun Microsystems.
  • In both single-server and multi-client network configurations, NFSv2 was the industry standard protocol for recovering from server crashes.
  • Because stateless protocols don’t keep any state information on the server, the server can provide all the information required to fulfill a client request.
  • Because NFS is so simple, it uses a stateless protocol.
  • File management: File handles allow a file or directory to be uniquely identified as the object of the current action.

Setting Up the NFS Server on Ubuntu ( Installing & Configuring)

install-&-configure-NFS-Mount-on-ubuntu

The following steps should help you install NFS mount on Ubuntu.

Step 1: Installing NFS Server on Ubuntu

We will start by installing the required components on each server.

On the Host

First, on the host server, install the nfs-kernel-server package to enable directory sharing. Since this is your first apt operation in this session, update your local package index before installation:

sudo apt update<br>sudo apt install nfs-kernel-server

After installing these packages, move on to the client server.

On the Client

Next, on the client server, install the nfs-common package, which provides NFS features without server components. Again, update the local package index before installation to ensure you have the latest information:

sudo apt update<br>sudo apt install nfs-common

Now that both servers have the required packages, we can proceed with the configuration.

Step 2 — Configuring & Creating Share Directories on the Host

We will create two different directories to share, each with unique configuration settings, to demonstrate two important ways NFS mounts can be set up regarding superuser access.

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

Superusers have full control over their system. However, NFS-mounted directories are not part of the system they are mounted on, so by default, the NFS server does not allow operations that need superuser privileges. This means that superusers on the client cannot write files as root, change ownership, or perform other superuser tasks on the NFS mount.

Sometimes, the trusted users on the client need to perform these actions on the mounted file system without needing superuser access on the host. You can set up the NFS server on ubuntu to allow this, but it does come with some risk, as such a user could potentially gain root access to the entire host system.

Step 3: Allow Client Systems to Access NFS Share

To set permissions for the NFS server, edit the /etc/exports file using your preferred text editor:

$ sudo vim /etc/exports

You can grant access to one client, several clients, or an entire subnet.

In this example, we have access to a whole subnet for the NFS share.

/mnt/nfs_share  192.168.43.0/24(rw,sync,no_subtree_check)  


Here’s what the options mean:

  • rw: Read/Write access.
  • sync: Changes must be written to the disk before they take effect.
  • no_subtree_check: Disables subtree checking.

To give access to a single client, use this format:

/mnt/nfs_share  client_IP_1 (rw,sync,no_subtree_check)  


For multiple clients, list each one separately:

/mnt/nfs_share  client_IP_1 (rw,sync,no_subtree_check)  
/mnt/nfs_share  client_IP_2 (rw,sync,no_subtree_check)  

Step 4: Export the NFS Share Directory

Once you have set access for the desired clients, export the NFS share directory and restart the NFS kernel server to apply the changes.

$ sudo exportfs -a<br>$ sudo systemctl restart nfs-kernel-server

Step 5: Allow NFS Access Through the Firewall

To enable client access to the NFS share, you must allow it through the firewall. Run this command:

$ sudo ufw allow from 192.168.43.0/24 to any port nfs

Reload or enable the firewall if it was off, and check its status. Ensure that port 2049, the default for file sharing, is open.

$ sudo ufw enable<br>$ sudo ufw status

Troubleshooting Common NFS Mount Issues

1. Cannot Access Files on a Mounted File System

First, verify if the file system is mounted. You can do this in several ways, but the best method is to check the file /proc/mounts, which shows all mounted file systems and their details. If that doesn’t work (for instance, if /proc is not available in your kernel), you can use the command mount -f, though it provides less information.

If the file system seems to be mounted, you might have another file system mounted on top of it. In that case, unmount and remount both volumes. Alternatively, if you exported the file system on the server before mounting it, NFS might be exporting the underlying mount point, and you would need to restart NFS on the server.

If the file system is not mounted, try to mount it.

2. Unable to mount a file system

When NFS mount on Ubuntu fails to connect to a volume, it usually shows two common errors:

1. failed, reason given by server: Permission denied

This indicates that the server does not recognize your access to the volume.

Check your /etc/exports file to ensure the volume is exported and that your client has the correct access type. For instance, if the client has only read access, you need to mount the volume using the ro option instead of rw.

  • Inform NFS of any changes to /etc/exports made since starting nfsd by running `exportfs -ra`. Check `/proc/fs/nfs/exports` to confirm volumes and clients are listed correctly. If they aren’t, you may need to re-export.
  • Verify the server recognizes your client; an outdated entry in `/etc/hosts` could cause confusion. Log into the server from the client using SSH or telnet, and ensure the client name matches the `/etc/exports` entry.
  • Test connectivity by pinging the client and vice versa.
  • Remember, you cannot export a directory and its subdirectory; export the parent directory with the required permissions instead.

3. NFS Performance Problems and Fixes

  • NFS uses a lot of CPU when moving large files, leading to slow write times.
  • Upgrading to a 2.4 kernel or using the no_wdelay option might help fix this.
  • You may see strange error messages if you try to change a file you can’t write to with NFS setattr.
  • NFS warnings show that the client-side RPC code has found timeouts and is reducing the number of active requests.
  • Startup/shutdown log errors for lockd are not serious and can be updated to support newer kernel features.
  • A file handle that is 16 bits instead of a multiple of 32 bits is not a problem, even if it looks odd.
  • If real permissions don’t match what’s in /etc/exports, it can cause the mount point to be locked.
  • Unreliable behavior may happen if ipchains are active on the server or client and fragmented packets are blocked.
  • If nfsd fails to start, check the /etc/exports file, verify the binaries, and make sure your kernel supports NFS server on Ubuntu.

Final Tips for a Smooth NFS Setup

By following this guide install NFS mount on Ubuntu seamlessly and have a fully functional NFS setup.

If you want to use NFS in a production environment, keep in mind that the protocol does not provide encryption. If you’re sharing data over a private network, this might not be an issue. However, in other situations, you will need a VPN or another type of encrypted tunnel to secure your data.

If you face issues, you can always tweak configurations, check logs and use security best practices.

FAQ’s

1. How can I confirm if NFS is installed on Ubuntu?

You can check if you have installed NFS Mount on Ubuntu by running this command:

which nfsd

If it gives you a path, then NFS is installed. If not, you can install it with sudo apt install nfs-kernel-server.

2. Is it possible to mount an NFS share on Windows?

Yes, Windows can use NFS. You need to install Services for NFS and then use the mount command to access the share.

3. Why is my NFS mount on Ubuntu set to read-only?

Look at the /etc/exports file to make sure the share has rw (read-write) permissions enabled.

4. How can I restart the NFS mount service?

You can restart it with this command:

sudo systemctl restart nfs-kernel-server

5. How do I forcefully unmount an NFS share?

If the share is unresponsive, you can forcefully unmount it using:

sudo umount -f /mnt/nfs_client_share

6. Is encryption supported by NFS?

NFSv4 does support encryption, but you may need to set up Kerberos authentication for better security.

7. How can I check active NFS connections?

You can run:

netstat -an | grep :2049

This will display active connections on the NFS port (2049).

Areeba Nauman
Areeba is a Content Writer with expertise in web content and social media, she can simplify complex concepts to engage diverse audiences. Fueled by creativity and driven by results, she brings a unique perspective and a keen attention to detail to every project she undertakes with her creativity and passion for delivering impactful content strategies for success. Let's connect on Linkedin: https://www.linkedin.com/in/areeba-bhatti/
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!