The easiest way to configure NFS sharing between two Linux machines
Let's make our first share from the server to the client. If you want to add more clients, just repeat Step #2 on all client computers. I have tried to make this guide as simple as possible, as all the other guides on the internet are too complicated.
The guide was created using the following parameters. Replace them with your own:
Share this folder from the server: /home/shareit
Mount the folder on client side: /mnt/share
Server IP: 192.168.0.100
Client IP: 192.168.0.101
Hint: You can check your IP by running the hostname -i command
Step #1: Configure the server side
- Install the required package(s):
Red Hat / CentOS: sudo yum install nfs-utils
Debian / Ubuntu: sudo apt install nfs-kernel-server rpcbind - Create a new exports file:
nano /etc/exports.d/mynewshare.exports - Add this line and save it:
/home/shareit 192.168.0.101(rw,sync,no_root_squash,no_all_squash) - Restart the service:
systemctl restart nfs-server
Step #2: Configure the client side
- Install the required package(s):
Red Hat / CentOS: sudo yum install nfs-utils
Debian / Ubuntu: sudo apt install nfs-kernel-server rpcbind - Create the mount folder:
mkdir -p /mnt/share - Grant full permission on this folder:
chmod -R 777 /mnt/share - Try the mount by running this command:
mount -t nfs 192.168.0.100:/home/shareit /mnt/share - If it works, unmount it, and make it permanent by editing fstab:
umount /mnt/share
nano /etc/fstab - Copy this line at the end of file, and save it:
192.168.0.100:/home/shareit /mnt/share nfs defaults 0 0 - Mount from fstab without reboot:
mount -a - Touch one file in the folder, and check the other side:
touch /mnt/share/feriman-com-tutorial
(Optional) Step #3: Debug
- If something is wrong, let's try to debug it on the server side. A useful command to check the exports file:
/usr/sbin/exportfs -a
Check ports on the firewall. Port 111 (TCP and UDP) and 2049 (TCP and UDP) are used for the NFS server.
sudo lsof -i -P -n | grep LISTEN - Check permissions on the folder on both sides:
ls -ltrhd /mnt/share
If you have any questions, leave a comment below.
Comments