sudo apt update
sudo apt install nfs-kernel-server
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/
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)
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
Update the system
sudo apt update
Install nfs-common packages
sudo apt install nfs-common
sudo mkdir -p /mnt/nfs
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
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
Autofs offers automounting functionality, automatically mounting the NFS directory when accessed.
sudo umount /mnt/nfs
sudo apt install autofs // for debian system
sudo pacman -S autofs // For arch system
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.
{% 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" %}