Install and configure NFS on Ubuntu 20.04

introduce:

NFS (Network File System) is a protocol for sharing file systems on a network. It allows you to share files and directories between different computers, providing a convenient file sharing and access mechanism. This article will guide you on how to install and configure NFS on Ubuntu 20.04.

Step 1: Install the NFS server component To use NFS on Ubuntu 20.04, you first need to install the NFS server component. Open a terminal and run the following command:

sudo apt update sudo apt install nfs-kernel-server

This will update the package list and install the NFS server components.

Step 2: Create a shared directory Next, you need to choose a directory to share. In this example, we will create a directory called "shared" as a shared directory. Open a terminal and run the following command:

sudo mkdir /shared sudo chmod -R 777 /shared

This will create a directory called "shared" and set its permissions to allow access for all users.

Step 3: Configure the NFS Share Now, you need to edit the configuration file of the NFS server to specify the shared directory. Open the file with your favorite text editor /etc/exports:

sudo vim /etc/exports

Add the following lines at the end of the file:

/shared *(rw,sync,no_subtree_check)

This will allow any host to access the shared directory in read-only mode.

Step 4: Reload the NFS configuration After completing the configuration changes, the NFS server needs to be reloaded for the changes to take effect. Run the following command:

sudo exportfs -a sudo systemctl restart nfs-kernel-server

This will reload the NFS configuration and restart the NFS server.

Step 5: Configure the NFS client To access NFS shares, you need to install the NFS client component on the client. Open a terminal on another Ubuntu 20.04 machine and run the following command:

sudo apt update sudo apt install nfs-common

This will install the NFS client components.

Step 6: Mount the NFS share On the client, you need to mount the NFS share to a local directory. First, create a directory for mounting. Open a terminal and run the following command:

sudo mkdir /mnt/shared

Then, mount the NFS share to that directory with the following command:

sudo mount server_ip:/shared /mnt/shared

Make sure to replace "server_ip" with the IP address of your NFS server. This will mount the NFS share to /mnt/sharedthe directory.

Guess you like

Origin blog.csdn.net/weixin_53000184/article/details/130799001