NFS allows you to share a directory with another server/client. It’s awesome.
This works great for VPC, or virtually connected servers, like Vultr Private Networking NFS.
In this tutorial we are connecting a CentOS 8 to an Ubuntu 18.04
I will show you how to do it both directions!
Note we are ALSO installing the client and server on BOTH. Kind of like a loop!
/mnt/share is the place we are going to read from
/opt/share is the place we are going share from
Add both server IP’s to the /etc/hosts on both machines. Use the internal IP’s if you are doing Private Networking.
# CentOS/RHEL 8 yum install epel-release -y yum install nfs-utils nfs4-acl-tools -y
# Ubuntu apt-get install nfs-kernel-server nfs-common -y
Then we need to have both of their IP’s on the hosts files.
# on both machines echo << EOF >> /etc/hosts 188.8.131.52 centos.guy 184.108.40.206 ubuntu.guy EOF
Now, have to pick one to share and which one to receive.
In this example I am sharing Ubuntu’s disk.
Then at the bottom I have another example of the opposite direction.
Share an Ubuntu 18.04 Drive via NFS
# Exporting server (Ubuntu 18.04) mkdir /opt/share chown nobody:nogroup /opt/share chmod 755 /opt/share cat << EOF >> /etc/exports /opt/share 220.127.116.11(rw,sync,no_subtree_check) EOF exportfs -r # open firewall to 18.104.22.168, or the IP that is going to read my drive ufw allow proto any from 22.214.171.124
CentOS will read it.
Read a CentOS 8 Drive via NFS
# Mounting server (CentOS 8) mkdir /mnt/share mount -t nfs 126.96.36.199:/opt/share /mnt/share
Share a CentOS 8 Drive via NFS
Doing the opposite (Share CentOS drive and read on Ubuntu)
# Exporting server (CentOS 8) mkdir /opt/share chown nobody:nobody /opt/share chmod 755 /opt/share cat << EOF >> /etc/exports /opt/share 188.8.131.52(rw,sync,no_subtree_check) EOF exportfs -r # open firewall to 184.108.40.206, or the IP that is going to read my drive firewall-cmd --zone=home --add-rich-rule='rule family="ipv4" source address="220.127.116.11" accept' firewall-cmd --permanent --add-service=nfs firewall-cmd --permanent --add-service=rpc-bind firewall-cmd --permanent --add-service=mountd firewall-cmd --reload # start the server systemctl enable --now nfs-server
Read an Ubuntu Drive via NFS
# Mounting server (Ubuntu 18.04) mkdir /mnt/share mount -t nfs 18.104.22.168:/opt/share /mnt/share
The only difference between the two sets of commands above are the following:
On CentOS you must chown the sharing folder as nobody:nobody
On Ubuntu you must chwon the sharing folder as nobody:nogroup
On CentOS you must run systemctl enable –now nfs-server
On Ubuntu you dont need to start the server
On CentOS 8, firewall-cmd is used to allow incoming connections.
On Ubuntu 18.04+, ufw is used to allow incoming connections.
Leave a Reply