NFS, or Network File System, is a distributed file system that allows users on a network to access files and directories on remote systems as if they were on the local system. NFS is often used in Linux environments to share files and directories between multiple systems, and it can be a convenient and efficient way to access and manage files on a network.
In this tutorial, we will show you how to install and configure an NFS server and client on Ubuntu 22.04. We will be setting up the NFS server on a system running Ubuntu 22.04, and the NFS client on a separate system also running Ubuntu 22.04.
Installing the NFS Server
To install the NFS server on Ubuntu 22.04, we first need to update the package index and install the nfs-kernel-server
package. This package provides the necessary components to run an NFS server on Ubuntu.
To update the package index and install the nfs-kernel-server
package, use the following command:
sudo apt update
sudo apt install nfs-kernel-server
After the package is installed, we need to configure the NFS server by editing the /etc/exports
file. This file is used to specify the directories that should be shared by the NFS server, and the clients that are allowed to access those directories.
To share the /mnt/nfs
directory with the NFS server, we can add the following line to the /etc/exports
file:
/mnt/nfs 192.168.1.0/24(rw,sync,no_subtree_check)
This line specifies that the /mnt/nfs
directory should be shared with the NFS server, and that clients on the 192.168.1.0/24
network are allowed to access the directory with read-write permissions.
After you have added the necessary lines to the /etc/exports
file, you can save the file and restart the NFS server to apply the changes.
sudo service nfs-kernel-server restart
The NFS server is now installed and configured, and it is ready to share the `/mnt
Installing the NFS Client
To access the files and directories shared by the NFS server, we need to install the NFS client on the client system. To do this, we can use the same apt
commands that we used to install the NFS server on the server system.
First, update the package index and install the nfs-common
package on the client system:
sudo apt update
sudo apt install nfs-common
After the nfs-common
package is installed, we can mount the shared directory on the client system. To do this, we need to create a mount point for the shared directory, and then use the mount
command to mount the directory.
For example, to mount the /mnt/nfs
directory shared by the NFS server on the /mnt/nfs-client
directory on the client system, we can use the following commands:
sudo mkdir /mnt/nfs-client
sudo mount 192.168.1.1:/mnt/nfs /mnt/nfs-client
This will mount the /mnt/nfs
directory from the NFS server on the /mnt/nfs-client
directory on the client system. The /mnt/nfs-client
directory will now be accessible on the client system, and you can access the files and directories in the shared directory as if they were on the local system.
To make the mount persistent across reboots, you can add an entry for the shared directory in the /etc/fstab
file on the client system. For example, to automatically mount the /mnt/nfs
directory from the NFS server on the /mnt/nfs-client
directory on the client system, you can add the following line to the /etc/fstab
file:
192.168.1.1:/mnt/nfs /mnt/nfs-client nfs defaults 0 0