Skip to content

NFS

Setup guide for sharing files over a local network using NFS between Linux and Unix-like systems.



  1. Install the NFS server package to enable file sharing.

    Terminal window
    sudo apt update && sudo apt install nfs-kernel-server -y
  2. Define the directory to share and specify client access in the NFS exports file.

    Terminal window
    echo "{{NFS_SHARE_VAR}} {{CLIENT_IP_VAR}}(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
  3. Reload the NFS exports to apply the changes.

    Terminal window
    sudo exportfs -ra
  4. Open the NFS port to allow access from the specified client IP.

    Terminal window
    sudo ufw allow from {{CLIENT_IP_VAR}} to any port nfs
  1. Install the NFS client package to enable mounting remote shares.

    Terminal window
    sudo apt update && sudo apt install nfs-common -y
  2. Make a local directory where the shared files will be mounted.

    Terminal window
    mkdir -p {{NFS_MOUNT_VAR}}
  3. Mount the shared directory manually from the server to the local mount point.

    Terminal window
    sudo mount {{SERVER_IP_VAR}}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}}
  4. Add an entry to /etc/fstab to mount the share automatically on boot.

    Terminal window
    sudo nano /etc/fstab
    Terminal window
    {SERVER_IP_VAR}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}} nfs noauto,x-systemd.automount,_netdev,nofail,timeo=5,retrans=2 0 0
  5. Unmount the shared directory. The -l (lazy) flag defers unmounting until the directory is no longer in use.

    Terminal window
    sudo umount -l {{NFS_MOUNT_VAR}}