NFS setting on LAN

In this post I describe how to set up a NFS file system on a local area newtwork: a NFS server blueberry (in this example a desktop with OpenSuse Leap 15.5 linux), exposing a directory path jupiter; and a NFS client strawberry (a Raspberry Pi with Debian buster linux). I am also showing how to use autofs to access jupiter.
These are the steps required:

  1.  Server side
    1. install the server nfs daemon. On OpenSuse Leap this is done with:
      sudo zypper install nfs-kernel-server
    2. Open port 2049 (nfs) on blueberry‘s firewall
    3. Declare the directories to be exported on the server.
      This is done by editing/adding the file /etc/exports with the following (example):
      /jupiter 192.168.1.0/255.255.255.0(rw,sync,no_root_squash,no_all_squash,no_subtree_check)
      Here the first element declares which directory to export. It is followed by the ip filter that allows all clients on the LAN and by a list of mounting options.
    4. restart the nfs daemon
  2. Client side
    1. Install nfs client on strawberry by:
      sudo apt-get install nfs-common
    2. Test that the client is working by mounting on a subdirectory of /mnt, like:
      sudo mkdir -p /mnt/jupiter
      sudo mount -v -t nfs blueberry:/jupiter /mnt/jupiter
      ls /mnt/jupiter
      The last statement should return a non-empty list of files/directories in the server nfs directory.
  3. Using autofs
    autofs allows automatic or lazy mounting of a directory. The mounting happens the first time that a path is required.

    1. install autofs on the client strawberry by: sudo apt-get install autofs
    2. create a directory path to hold the mount point, like sudo mkdir -p /mnt/nfs/jupiter
    3. edit the file /etc/auto.master by creating the mapping to the appropriate configuration file.
      Add the following to the file:
      /mnt/nfs /etc/auto.nfs
      This tells autofs that the mounting of mount-point /mnt/nfs is determined by the configuration /etc/auto.nfs
    4. Create the file /etc/auto.nfs, if its does not exists already, and add the following:
      jupiter -fstype=nfs4,rw blueberry:/jupiter
      This tells autofs to mount the mount point /mnt/nfs/jupiter pointing to jupiter directory on the server blueberry using mount options -fstype=nfs4,rw
    5. Test it by ls /mnt/nfs/jupiter. It should work without the need of explicit mounting.