How To Setup NFS server on Ubuntu 24.04

NFS stands for Network File System is a network file-sharing protocol that allows you to share files and directories over the network. You can mount the file systems over a network and use them as your local drive. NFS server is a client-server architecture where multiple clients can mount the shared drive from the NFS server and share resources between Linux systems. By using NFS, you can save space and the cost of storage, especially when you are using cloud instances.

In this guide, You will learn how to set up the NFS server on Ubuntu 24.04.

Prerequisites

1. A server running Ubuntu and having a static IP address with root privileges.

2. A client running Ubuntu with sudo privileges.

Step 1: Update OS

Before starting the NFS server installation, update your base system by executing the following command:

Step 2: Install and configure the NFS Server

On your server system, install nfs-kernel-server package by running the following command:

Now, start the NFS service and enable it to auto-start at system boot time. Then, verify the NFS service status with the following command:

Output:

Step 3: Create and Export NFS share Directory

Next, you need to create an NFS share directory on your NFS server that you want to access on your client’s system. Execute the below command to create a shared directory:

Now, create some files in that shared directory:

Next, Set proper permissions on NFS share directory:

Now, set the permission to read, write, and execute permissions to all the files inside the shared directory.

Step 4: Configure the Export Directory

Now, edit the NFS server configuration file and define the path of the directory that you want to share. To edit the file, run the following command:

Now add the following line:

Here, You need to replace the IP address with your client’s IP address. For multiple clients, you need to specify the separate line as shown below:

You have to define permission for each client.

rw: The client can read and write on the shared directory.

Sync: This will reply to requests only after the changes have been committed to stable storage.

no_subtree_check: Do not check subtree.

After setting up the access permission to each client, you need to export the NFS share directory.

To apply the changes, you have made, you need to restart the service using the command below:

Step 5: Install and Configure NFS Client

You have set up and configured the NFS service on the server but, you need to install the following packages on your client system to configure the NFS client:

Now, start the nfs-client service, enable it at system reboot, and then check the service status by running the following command in the terminal:

Output:

Now, on the client system, you can see the mount information of the NFS server using the following command:

Here, you need to replace the IP address with your NFS server IP address.

Output:

Step 6: Create and mount NFS share on the client

Now, create a directory on the client system using the command below:

Next, mount the NFS server shared directory on the NFS client by running the command below:

Here, replace the IP address with your NFS server IP address.

To mount the NFS file system permanently even after a system reboot, then update /etc/fstab the file on your NFS client system.

Then add the below line with your NFS server IP address and NFS directory name:

Output:

Now, the NFS file system is automatically mounted at system reboot.

Step 7: Verify the NFS share on the client system

Let’s verify the NFS mount point on the NFS client system by using the df -h command:

Output:

You can see your server IP address followed by the shared directory path in your mount point as highlighted in the above output.

Let’s now create a file on the NFS mount directory /mnt/nfs_share_mount from the NFS client system.

Here, we have created file3 from the NFS client system, Now login into the NFS-server and check the NFS directory list:

Output:

You can see the same file has been accessible on both systems and the NFS server is working fine.

Conclusion

Congratulations! You have successfully set up the NFS server on Ubuntu, and you also learned how to access the NFS share from the client machine. Please have no hesitation to ask me if you have any queries.

Leave a Reply

Your email address will not be published. Required fields are marked *