NFS: -
NFS is Network File System, It allow us to share file between Linux systems. Using NFS we can mount local folder to a remote Server and can work as a local directory.
Why Use NFS: -
o- NFS can help us to access remote file on local linux system.
o- We can Setup Centralize storage using NFS
o- We can secure our data access with the help of NFS.
Prerequisites:-
1- Server IP- 192.168.102.11
2- Client IP- 192.168.102.10
Setup and configure NFS Share: -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Server Side Configuration:
Step 1: - Install NFS Package
Before we start NFS configuration, first we need to install NFS package. let's install required packages using the command below:
root@Server16:~# apt install nfs-kernel-server
Step 2: - Create a Shared Directory and change owner
we need to create a directory first that we will share with the client. Use command below to create a directory-
root@Server16:~# mkdir /home/nfsshare
Change owner of directory use below command.
root@Server16:~# chown nobody:nogroup /home/nfsshare/
Step 3: - Configure export directory
For sharing a directory, we need to make an entry into /etc/export configuration file.
Let's modify export configuration file using command below
root@Server16:~# vi /etc/exports
Append highlighted line in the end of configuration file as below
Save and Exit from the file.
Where switches as follow:
rw = This option allows the client computer to read and write.
sync = This option allows NFS to write changes back to disk
no_subtree_check = By default, NFS translates requests from a root user remotely into a non-privileged user on the server. This was intended as a security feature to prevent a root account on the client from using the file system of the host as root. no_root_squash disables this behaviour for certain shares
Step 4: - Restart NFS Server Service to apply changes:
root@Server16:~# systemctl restart nfs-server.service
.
Step 5: - Adjust Firewall in case it's not disabled.
Check Firewall Status using the command below
root@Server16:~# ufw status
Status: inactive
In my case, it is inactive, if it is active then run the command below to allow NFS access.
root@Server16:~# ufw allow from 192.168.102.10 to any port nfs
Rules updated
Reload Firewall service to apply changes
root@Server16:~# ufw reload
Firewall reloaded
Client Side Configuration:
Step 6: - Install NFS client package
Before we start mounting, First we need to install nfs-common package on the client system let do it by hitting command below.
root@US16:~# apt install nfs-common
Step 7: - Create the mount point Client end.
we need to create mount point first, let do it by hitting command below.
root@US16:~# mkdir /mnt/nfserver
Step 8: - Mount NFS share on the Client end.
Now that we have some place to put the remote shares and we've opened the firewall, we can mount the shares by addressing our host server,root@US16:~# mount -t nfs 192.168.102.11:/home/nfsshare /mnt/nfserver/
Step 9: - Test NFS Share by creating directory or files:
NFS Client Side
Use command df -h to list mounted point:
root@US16:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.2M 97M 4% /run
/dev/mapper/US16--vg-root 6.3G 2.8G 3.3G 46% /
192.168.102.11:/home/nfsshare 6.6G 5.8G 471M 93% /mnt/nfserver
Create test directory to the mounted folder
root@US16:/mnt/nfserver# mkdir testnfs/
NFS Server Side
Let's check created directory at NFS SERVER
root@Server16:~# ls -la /home/nfsshare/
total 12
drwxr-xr-x 3 nobody nogroup 4096 Jul 7 16:22 .
drwxr-xr-x 10 root root 4096 Jul 7 15:07 ..
drwxr-xr-x 2 nobody nogroup 4096 Jul 7 16:22 testnfs
NFS Share working as expected
Step 10: - Create fstab entry to mount NFS share permanently
We can mount any NFS share by mount command but it's temprory mounting and will unmount once system reboot, To solve this problem let's make a fstab file entry to mount permanently.
root@US16:~# vi /etc/fstab
Append the line below into the file fstab
192.168.102.11:/home/nfsshare /mnt/nfsserver nfs defaults 0 0
save and exit form the file.
Step 11:- Apply make changes of fstab file using below command.
We need to reboot system after making changes into fstab file, but let's use command mount -a to apply changes.
root@US16:~# mount -a
Let's check mount point using below command.
root@US16:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.2M 97M 4% /run
/dev/mapper/US16--vg-root 6.3G 2.8G 3.3G 46% /
192.168.102.11:/home/nfsshare 6.6G 5.8G 471M 93% /mnt/nfserver
No comments:
Post a Comment