Network File System (NFS) is a distributed file system protocol that allows you to share files and directories across multiple systems. It is commonly used in Linux and Unix-based operating systems and allows users to access files and directories on a remote system as if they were local. In this tutorial, we will show you how to install and configure an NFS server on Ubuntu.
Step 1: Installing NFS Server
To install the NFS server on Ubuntu, you will need to use the apt package manager. Open a terminal window and enter the following command:
sudo apt-get install nfs-kernel-server
This will install the necessary packages to run an NFS server on Ubuntu.
Step 2: Configuring NFS Server
Once the NFS server is installed, you will need to configure it to share specific directories. The main configuration file for NFS is /etc/exports. This file contains a list of directories that are exported by the NFS server.
To add a directory to be exported by the NFS server, open the /etc/exports file in a text editor with root privileges, for example:
sudo nano /etc/exports
Add the following line to the file to export the directory /var/nfs, allowing access to all IP addresses with read-write permissions:
/var/nfs *(rw,sync,no_subtree_check)
You may export other directories in the same way, just make sure to have each directory on a new line.
Step 3: Starting the NFS Server
Once the NFS server is configured, you can start the service by running the following command:
sudo service nfs-kernel-server start
You can check the status of the NFS server by running the following command:
sudo service nfs-kernel-server status
Step 4: Mounting NFS share on client
Now that the NFS server is up and running, you can mount the shared directory on a client machine. To mount the shared directory, you will need to use the mount command.
On the client machine, create a directory where the shared directory will be mounted:
sudo mkdir /mnt/nfs
Mount the shared directory by running the following command:
sudo mount <NFS-server-ip-address>:/var/nfs /mnt/nfs
You can check if the shared directory is mounted by running the following command:
df -h
You should see the shared directory listed in the output.
This is a basic example of how to install and configure an NFS server on Ubuntu. You can configure the NFS server to share multiple directories and use different options and permissions depending on your needs. Keep in mind that NFS is a network service, therefore, make sure you have a properly configured firewall and also secure your NFS server with appropriate permissions.
In conclusion, NFS is a powerful and flexible distributed file system that is widely used in Linux and Unix-based operating systems. It allows you to share files and directories across multiple systems, making it easy to share data between multiple users and systems. With the steps outlined in this tutorial, you should now be able to install and configure an NFS server on Ubuntu and mount the shared directory on a client machine.