How to configure NFS in Ubuntu/CentOS-
What is NFS -
NFS stands for Network File System, developed by Sun Microsystems. By using this protocol a user on a client computer can access files over a computer network much like local storage is accessed.
Let’s start with configuration -
First, we need to install the required packages. Tp install NFS package we need to run following command -
# apt install nfs-kernel-server => For Ubuntu
# yum install nfs nfs-utils => For CentOS/RedHat
Now create a directory that you want to share over the network.
# mkdir /nfsshare
Now change the permission of shared directory as bellow-
# chmod 777 /nfsshare
After all this, we need to make an entry in exports file-
# vim /etc/exports
/nfsshare *(rw,sync)
Save and exit.
Note - ‘*’ denotes that shared directory available for all networks, instead of * we can give a particular IP address or domain name.
‘rw’ means read-write permission.
‘sync’ means it will synchronize the data real-time basis.
We can add more arguments on the basis of needs like ‘sec’ for security.
Now start and enable the services.
# systemctl start/enable nfs-server.service => For CentOS/RedHat
# systemctl start nfs-kernel-server
Now export the shared directory -
# exportfs -rv
Add the firewall rules- => For CentOS/RedHat
# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --permanent --add-service=mountd
# firewall-cmd --reload
For Ubuntu -
# ufw allow nfs
Now start with the client configuration.
To see the shared directory we need to run following command -
# showmount -e <” server IP address”>
To mount NFS share in the client we need to follow these steps
First, we need to install nfs-utils packages in centos for ubuntu no need to install it’s already there.
# yum install nfs-utils
Now edit fstab file and the following line-
192.168.0.110:/nfsshare /mnt auto defaults 0 0
Save and exit
If you guys have any doubts comment below otherwise you can send me an Email - johntheh4cker
Comments