NFS Mount

How To Set Up an NFS Mount on Ubuntu 24.04

Network File System (NFS) is a powerful protocol that allows you to share files and directories over a network. With NFS, you can easily access files on distant machines as if they are located on your own server. In this blog post, we will guide you through the steps to set up an NFS mount on Ubuntu 24.04, ensuring that you can share and access files seamlessly across your systems.

Prerequisites

Before we get started, make sure you have the following:

  1. An Ubuntu 24.04 server (or client) where NFS will be installed.
  2. Administrative (sudo) access to the server.
  3. The IP address of the server that will act as the NFS server (the one with shared directories).
  4. Basic knowledge of terminal commands.

Step 1: Install the NFS Server on Ubuntu

If you’re setting up an NFS server, begin by installing the necessary package on the server machine. Open your terminal and execute the following commands:

sudo apt update
sudo apt install nfs-kernel-server

Once the installation is complete, you can verify that the NFS server is running by executing:

sudo systemctl status nfs-server

You should see output indicating the NFS server is active.

Step 2: Create a Shared Directory

Next, you need to create a directory that you want to share over the network. For example, we will create a directory named nfs_share:

sudo mkdir -p /srv/nfs/nfs_share

Change the permissions of this directory to allow access:

sudo chown nobody:nogroup /srv/nfs/nfs_share
sudo chmod 777 /srv/nfs/nfs_share

Step 3: Configure NFS Exports

Now you need to configure the NFS exports to specify which directories will be shared and their permissions. Open the exports file in a text editor:

sudo nano /etc/exports

Add the following line to the file, replacing <CLIENT_IP> with the actual IP address of your NFS client machine, or use * to allow any client:

/srv/nfs/nfs_share <CLIENT_IP>(rw,sync,no_subtree_check)

The options mean:

  • rw: Read and write access.
  • sync: Ensures that changes are written to disk before the operation completes.
  • no_subtree_check: Disables subtree checking, which improves performance in some scenarios.

To apply the changes, execute:

sudo exportfs -a

Step 4: Start and Enable the NFS Service

Ensure that the NFS server starts automatically on boot and is currently running. Use the following commands:

sudo systemctl enable nfs-server
sudo systemctl start nfs-server

To allow NFS through the firewall, execute:

sudo ufw allow from <CLIENT_IP> to any port nfs

Step 5: Install NFS Client on Ubuntu

On the client machine, you need to install the NFS packages as well. Run:

sudo apt update
sudo apt install nfs-common

Step 6: Create a Mount Point on the Client

Next, create a mount point where you will access the shared directory. For example:

sudo mkdir -p /mnt/nfs_share

Step 7: Mount the NFS Share

You can now mount the NFS share using the following command, replacing <SERVER_IP> with the IP address of your NFS server:

sudo mount <SERVER_IP>:/srv/nfs/nfs_share /mnt/nfs_share

To verify that the mount was successful, you can use the df -h command:

df -h

You should see your NFS share listed in the output.

Step 8: Configure Automatic Mounting at Boot (Optional)

To ensure that the NFS share mounts automatically after a system reboot, you can add an entry to the /etc/fstab file on your client:

sudo nano /etc/fstab

Add the following line:

<SERVER_IP>:/srv/nfs/nfs_share /mnt/nfs_share nfs defaults 0 0

Save and exit the file. Now, your NFS share will be mounted automatically on boot.

Conclusion

Setting up an NFS mount on Ubuntu 24.04 is a straightforward process that can greatly enhance your file-sharing capabilities across networks. Just follow these simple steps, and you’ll be able to share files seamlessly between systems. Whether you’re running a home media server or managing a network of machines, NFS is a reliable and efficient option.