The easiest way to configure NFS sharing between two Linux machines

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

  1. Install the required package(s):
    Red Hat / CentOS: sudo yum install nfs-utils
    Debian / Ubuntu: sudo apt install nfs-kernel-server rpcbind

  2. Create a new exports file:
    nano /etc/exports.d/mynewshare.exports

  3. Add this line and save it:
    /home/shareit 192.168.0.101(rw,sync,no_root_squash,no_all_squash)

  4. Restart the service:
    systemctl restart nfs-server

Step #2: Configure the client side

  1. Install the required package(s):
    Red Hat / CentOS: sudo yum install nfs-utils
    Debian / Ubuntu: sudo apt install nfs-kernel-server rpcbind

  2. Create the mount folder:
    mkdir -p /mnt/share

  3. Grant full permission on this folder:
    chmod -R 777 /mnt/share

  4. Try the mount by running this command:
    mount -t nfs 192.168.0.100:/home/shareit /mnt/share

  5. If it works, unmount it, and make it permanent by editing fstab:
    umount /mnt/share
    nano /etc/fstab

  6. Copy this line at the end of file, and save it:
    192.168.0.100:/home/shareit /mnt/share nfs defaults 0 0

  7. Mount from fstab without reboot:
    mount -a

  8. Touch one file in the folder, and check the other side:
    touch /mnt/share/feriman-com-tutorial

(Optional) Step #3: Debug

  1. 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

  2. Check permissions on the folder on both sides:
    ls -ltrhd /mnt/share

 

If you have any questions, leave a comment below.

Comments