How to install and configure an nfs server on ubuntu 22. 04

How to Install and Configure an NFS Server on Ubuntu 22.04

Network File Share or NFS is a protocol utilized for sharing files and directories over a network of Linux clients including Ubuntu 22.04 systems. Basically, a shared directory is created and files are added to it so that the client can easily access them. Using NFS is also considered an ideal approach when it is required to exchange common data between different client systems.

This blog will demonstrate the procedure of installing and configuring the NFS server on Ubuntu 22.04. Let’s get started.

Note: In our post, we will refer “linuxuser” as our NFS server and “ubuntuuser” machine as NFS client.

InstalIing
Sponsored
NFS server on Ubuntu 22.04

For the purpose of installing the NFS server on Ubuntu 22.04, follow the given instructions.

Step 1: Update system packages

First of all, hit “CTRL+ALT+T” and update the system packages by running provided command:

$ sudo apt update

All packages are updated:

How to install and configure an nfs server on ubuntu 22. 04 1

Step 2: Install NFS server

In the next step, run the below-given command in the Ubuntu 22.04 terminal for NFS server installation:

$ sudo apt install nfs-kernel-server

How to install and configure an nfs server on ubuntu 22. 04 2

The given output indicates that NFS server is successfully installed on Ubuntu 22.04 “linuxuser”system:

How to install and configure an nfs server on ubuntu 22. 04 3

Now, let’s move toward the procedure to configure the installed NFS server.

Configuring NFS server on Ubuntu 22.04

For the configuration of the NFS server on Ubuntu 22.04, follow the given instructions.

Step 1: Make shared NFS directory

First of all, we will create a directory named “nfs_share” that is going to be shared by all client systems. To do so, write out the following command:

$ sudo mkdir -p /mnt/nfs_share

How to install and configure an nfs server on ubuntu 22. 04 4

Step 2: Set directory permissions

Next, set the permissions of the created “nfs_share” directory so that all client machines can easily access it:

$ sudo chown -R nobody:nogroup /mnt/nfs_share/

How to install and configure an nfs server on ubuntu 22. 04 5

Now, move to next step.

Step 3: Set file permissions

Set the file permissions as required. In our case, we have allocated the read, write, and execute permissions to the “nfs_share” directory files:

$ sudo chmod 777 /mnt/nfs_share/

How to install and configure an nfs server on ubuntu 22. 04 6

Step 4: Grant NFS access

In this step, we will grant access to the client system for accessing the NFS server. To do so, open “/etc/exports” in the “nano” editor:

$ sudo nano /etc/exports

How to install and configure an nfs server on ubuntu 22. 04 7

Now, it is up to you whether you want to grant access to the entire subnet, single or multiple clients. For instance, we will permit an entire subnet “10.0.2.15/24” to access the NFS share:

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

How to install and configure an nfs server on ubuntu 22. 04 8

After adding the required line, press “CTRL+O” to save the file and switch back to the Ubuntu 22.04 terminal.

Step 5: Exporting NFS directory

Utilize the provided command for exporting the NFS shared directory:

$ sudo exportfs -a

How to install and configure an nfs server on ubuntu 22. 04 9

Step 6: Restart NFS server

Write out the provided command for restarting the NFS server on your Ubuntu 22.04 system:

Sponsored
$ sudo systemctl restart nfs-kernel-server

How to install and configure an nfs server on ubuntu 22. 04 10

Step 7: Grant Firewall access

Next, grant the Firewall access to the client system with the following “ufw” command:

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

How to install and configure an nfs server on ubuntu 22. 04 11

Step 8: Enable Firewall

Enable Firewall with “ufw” command and “enable” option:

$ sudo ufw enable

How to install and configure an nfs server on ubuntu 22. 04 12

Step 9: Check Firewall status

Next, verify that the Firewall is configured to allow the access through the port “2049”:

$ sudo ufw status

How to install and configure an nfs server on ubuntu 22. 04 13

We will now head towards the NFS client on “ubuntuuser” system to test the NFS sharing point.

Installing NFS client on Ubuntu 22.04

In order to perform NFS client installation on Ubuntu 22.04, hit “CTRL+ALT+T” and run the following command:

$ sudo apt install nfs-common

How to install and configure an nfs server on ubuntu 22. 04 14

Testing NFS share on Ubuntu 22.04

Now, we will test the access co-ordination between NFS client “ubuntuuser” and “linuxuser” NFS server. To do so, create a mount point on the NFS client system:

$ sudo mkdir -p /mnt/nfs_clientshare

How to install and configure an nfs server on ubuntu 22. 04 15

Then, mount the NSF share on the other Client system:

$ sudo mount 10.0.2.15:/mnt/nfs_share /mnt/nfs_clientshare

How to install and configure an nfs server on ubuntu 22. 04 16

For the testing NFS share on the client system, firstly, we will create some files in the “nfs_share” directory on the “linuxuser” NFS server:

$ cd /mnt/nfs_share/

How to install and configure an nfs server on ubuntu 22. 04 17

$ touch sample1.text sample2.text

How to install and configure an nfs server on ubuntu 22. 04 18

Then, switch to the client system and view the list of files present in the “nfs_clientshare” directory:

$ ls -l /mnt/nfs_clientshare/

The given output indicates that files are successfully accessed on “ubuntuuser” client via NFS server:

How to install and configure an nfs server on ubuntu 22. 04 19

Uninstalling NFS server on Ubuntu 22.04

For the uninstallation of NFS server, run the following command:

$ sudo apt remove nfs-kernel-server

How to install and configure an nfs server on ubuntu 22. 04 20

Uninstalling NFS client on Ubuntu 22.04

For the uninstallation of NFS client, write out the following command in Ubuntu 22.04 terminal:

$ sudo apt remove nfs-common

How to install and configure an nfs server on ubuntu 22. 04 21

We have compiled the method to install, configure, and test NFS server on Ubuntu 22.04.

Conclusion

For the purpose of installing NFS server on Ubuntu 22.04, firstly, update system packages and run the “$ sudo apt install nfs-kernel-server” command. Then create a shared NFS directory, set the file and directory permissions, and export it. Next, install the NFS client on another system with “$ sudo apt install nfs-common” command, create a mount point, and test the access of the shared NFS directory. This blog demonstrated the method of installing, configuring, and testing the NFS server on Ubuntu 22.04.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply