Setting up NFS Server and Client

Setting up NFS Server and Client

Creating a Shared Network Drive with NFS on Ubuntu: A Comprehensive Guide

In this guide, we will set up the NFS server in ubuntu server 22.04 and access files from the client ubuntu GUI 22.04

Steps

  1. Install the nfs-kernel-server

  2. Create a directory on the server that you want to share with the client

  3. Grant appropriate permissions to the shared directory

  4. Edit the /etc/exports file to specify the directory and file you want to share with the client.

  5. export the shared directory

  6. Restart the NFS server

  7. Install the nfs-common on client machine

  8. create a directory and mount. on client machine

  9. create content inside it and verify

Let's setup the NFS server first

Install the nfs-kernel-server package by running the following command in the terminal

sudo apt-get update
sudo apt-get install nfs-kernel-server

Verify the installation

and create a directory you want to share with the client. For example, let's create a directory called shared inside the root directory

sudo mkdir /shared

Grant appropriate permissions to the shared directory by running the following command

sudo chown nobody:nogroup /shared
sudo chmod 777 /shared

Edit the /etc/exports file to specify the directory and file you want to share with the client. Add the following line to the end of the file

Save and exit the file, and then run the following command to export the shared directory

sudo exportfs -a

Restart the service

sudo systemctl restart nfs-kernel-server

Setting up Client

Install the nfs-common package by running the following command in the terminal

sudo apt-get update
sudo apt-get install nfs-common

Create a directory on the client machine to mount the shared directory. For example, let's create a directory called mnt in root

Mount the shared directory on the client machine and Verify that the shared directory has been mounted by running the following commands

sudo mount SERVER_IP:/shared /mnt
df -h

Change the directory to /mnt Create a file and add some content to it

I am creating a file name hello.txt and add content hello world

verify the file in the server,

cleanup (unmount the shared directory)

sudo umount server-ip:/shared /mnt

Did you find this article valuable?

Support Muhammad Usama by becoming a sponsor. Any amount is appreciated!