Skip to content

NFS

Setup guide for sharing files using NFS between Ubuntu systems.


Server

  1. Install

    Install the NFS server package to enable file sharing.

    Terminal window
    sudo apt update && sudo apt install nfs-kernel-server -y
  2. Add export

    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. Apply export

    Reload the NFS exports to apply the changes.

    Terminal window
    sudo exportfs -ra
  4. Allow through firewall (optional)

    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

Client

  1. Install

    Install the NFS client package to enable mounting remote shares.

    Terminal window
    sudo apt update && sudo apt install nfs-common -y
  2. Create mount point

    Make a local directory where the shared files will be mounted.

    Terminal window
    mkdir -p {{NFS_MOUNT_VAR}}
  3. Manual mount

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

    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