close
close
ubuntu 24.04 install nfs

ubuntu 24.04 install nfs

3 min read 25-11-2024
ubuntu 24.04 install nfs

Network File System (NFS) is a powerful tool that allows you to share directories and files over a network. This collaborative file system is particularly useful in a Linux environment, enabling users to easily access shared files across different machines. In this article, we'll walk you through the installation and configuration of NFS on Ubuntu 24.04.

What You Need Before You Start

Before diving into the installation, ensure that you have the following prerequisites:

  • A system running Ubuntu 24.04.
  • Administrative (sudo) access to the system.
  • Two systems to demonstrate NFS: one as the NFS server and another as the NFS client.

Step 1: Update Your System

It's always good practice to start with the latest updates. Open your terminal and execute:

sudo apt update && sudo apt upgrade -y

This command updates the package list and upgrades the installed packages on your system.

Step 2: Install the NFS Server Package

To set up NFS on the server, you need to install the NFS kernel server package. Run the following command:

sudo apt install nfs-kernel-server -y

Step 3: Configure the NFS Exports

Once the installation is complete, you need to define which directories to share and with whom. You can do this by editing the /etc/exports file.

  1. Open the exports file in a text editor:
sudo nano /etc/exports
  1. Add the directories you want to share. For example, if you want to share a directory called /mnt/nfs with read/write permission for a client with IP address 192.168.1.100, add the following line:
/mnt/nfs 192.168.1.100(rw,sync,no_subtree_check)

Explanation of Options

  • rw: Allows read and write permissions.
  • sync: Ensures changes are written to disk before responding.
  • no_subtree_check: Prevents NFS from checking if the shared directory is a subtree of the exported path, which improves performance.
  1. After editing, save the file (press CTRL + X, then Y, and hit Enter).

Step 4: Create the Shared Directory

Now, create the directory you defined in the exports file. Execute:

sudo mkdir -p /mnt/nfs

Change the ownership of this directory for testing purpose:

sudo chown nobody:nogroup /mnt/nfs

Step 5: Export the Shared Directory

To apply the changes made to the exports file, run the following command:

sudo exportfs -a

Step 6: Start and Enable NFS Services

Ensure that the NFS server service is running and set to start on boot using the following commands:

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

Step 7: Configure the NFS Client

Now that the server is ready, switch to your NFS client machine (with IP 192.168.1.100 in our example) and install the NFS client package:

sudo apt install nfs-common -y

Step 8: Create a Mount Point

On the NFS client, create a mount point where the shared directory will be accessible:

sudo mkdir -p /mnt/nfs_client

Step 9: Mount the NFS Share

To mount the shared directory, run the following command from the client:

sudo mount 192.168.1.XX:/mnt/nfs /mnt/nfs_client

(Replace 192.168.1.XX with the actual IP address of your NFS server.)

Step 10: Verify the NFS Share

You can check to see if the mount was successful by executing:

df -h

You should see the NFS share listed in the output. You can also navigate to the mounted directory to check:

cd /mnt/nfs_client
ls

Step 11: Auto-Mount NFS Share on Boot

To ensure that the NFS share mounts automatically on system startup, you can add an entry to the /etc/fstab file on the NFS client.

  1. Open the fstab file:
sudo nano /etc/fstab
  1. Add the following line at the end of the file:
192.168.1.XX:/mnt/nfs /mnt/nfs_client nfs defaults 0 0

(Again, replace 192.168.1.XX with your NFS server's IP.)

  1. Save the changes and exit.

Conclusion

You have successfully installed and configured NFS on Ubuntu 24.04! Your systems can now share files seamlessly over the network. NFS is a robust and efficient file sharing solution, ideal for environments requiring centralized file access. By following these steps, you can enhance collaboration and improve workflow efficiency within your network. For any questions or further assistance, feel free to reach out to the community!

Related Posts


Latest Posts


Popular Posts