Skip to content

Latest commit

 

History

History
195 lines (117 loc) · 4.46 KB

nfs-server.md

File metadata and controls

195 lines (117 loc) · 4.46 KB

NFS Server

Install NFS Server

Step 1: Install nfs-kernel on the ubuntu

sudo apt update
sudo apt install nfs-kernel-server

Step 2: Create an nfs repository

Create a nfs folder

mkdir /mnt/nfs

To enable access for all client machines to the shared directory, eliminate any constraints within the directory permissions.

sudo chown -R nobody:nogroup /mnt/nfs

You can also tweak the file permissions to your preference. Here’s we have given the read, write and execute privileges to all the contents inside the directory.

sudo chmod 777 /mnt/nfs/

Step 3: Grant nfs directory access to clients

To allow access for all client machines to the shared directory, remove any existing restrictions in the directory permissions.

sudo mv /etc/exports /etc/exports.orig

Create a new file

sudo vi /etc/exports

Add the following content in /etc/exports file

/mnt/nfs  192.168.0.0/24(rw,sync,no_subtree_check)

Step 4: Export the nfs directory

After granting access to the preferred client systems, export the NFS share directory and restart the NFS kernel server for the changes to come into effect.

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

Install the NFS Client on the Client Systems

Step 1: Install basic packages

Update the system

sudo apt update

Install nfs-common packages

sudo apt install nfs-common

Step 2: Create an NFS Mount Point on Client

sudo mkdir -p /mnt/nfs

Step 3: Mount NFS Share on Client System

To check if the server is exporting any directories, use the following command.

showmount --export <server_ip_addr>

Now mount the nfs directory to your directory

sudo mount <ip_add>:/mnt/nfs /mnt/nfs

Step 4: Check the connection.

Add some files on server side.

cd /mnt/nfs
vim test1.txt

Now, verify the presence of the files on the client side.

ls -l /mnt/nfs

Installing Autofs

Autofs offers automounting functionality, automatically mounting the NFS directory when accessed.

Step 1: Un-mount the nfs directory

sudo umount /mnt/nfs

Step 2: Install autofs on your system

sudo apt install autofs // for debian system
sudo pacman -S autofs // For arch system

Step 3: Autofs Configurations

Edit the file '/etc/autofs.master' or '/etc/autofs/autofs.master' and add the following content.

/mnt/nfs /etc/autofs/autofs.nfs --ghost --timeout=60

Create the file '/etc/autofs/autofs.nfs' or '/etc/autofs.nfs'. Additionally, establish a 'backups' folder on the server side.

backups -fstype=nfs4,rw 192.168.0.106:/mnt/nfs

Delete all mount points and restart the autofs service.

Check whether the NFS server is mounted or not.

The NFS server is currently not mounted. Now attempt to access the NFS directory.

The NFS server is now accessible, and it is mounted automatically when accessed.

Source / Documentation

{% embed url="https://www.tecmint.com/install-nfs-server-on-ubuntu/" %}

{% embed url="https://medium.com/@osa_/how-to-set-up-an-nfs-server-and-client-in-an-ubuntu-environment-to-share-files-directories-388083f2fd3e" %}

{% embed url="https://www.youtube.com/watch?v=Na_jKeVWzrc&t=569s" %}