Sharing data over SMB is one of the most common way, and the other is NFS, NFS approach is pretty simplistic rather than SMB, add some line to config file and re-exports.

Installing packages
  1. Install nfs packages
    $ sudo apt install nfs-common nfs-kernel-server
Configuring NFS
  1. The only file we to modify is /etc/exports
    $ sudo nano /etc/exports
  2. We will see many commented lines and sample of configuration line
    # /etc/exports: the access control list for filesystems which may be exported
    #               to NFS clients.  See exports(5).
    #
    # Example for NFSv2 and NFSv3:
    # /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
    #
    # Example for NFSv4:
    # /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
    # /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
    #
  3. Then we just need add our line to share, here i attach 3 example my most common used, there is many other tweaks for advanced options, lookup to NFS Man Page
    # example 1, this is the simplest form
    /media/hgst    192.168.0.0/24(rw,async,no_subtree_check)
    # example 2, as NFS by default prevent root intervention, like chown chmod, but sometimes we need it then we can add options to remove root denial, or called by `root squash`
    /opt/someapp/someapp-config 192.168.0.0/24(rw,async,no_subtree_check,no_root_squash)
    # example 3, deny all user, except `UID 1000`, in this case we must ensure that all the directory and file writeable and readable by `UID 1000`
    /opt/someapp/someapp-config 192.168.0.0/24(rw,async,no_subtree_check,all_squash,anonuid=1000,anongid=1000)
  4. Lastly after we adding line then we refresh the exports
    $ sudo systemctl restart nfs-server.service
    Mounting NFS share
  5. Install nfs package
    $ sudo apt install nfs-common
  6. Add line to /etc/fstab
    192.168.0.2:/opt/someapp/someapp-config /media/nfs nfs4 defaults 0 0

    Notice the IP and the path, nfs-host-ip:/shared/path /destination/path replace to suit your host ip and shared path. Don't forget to create the /destination/path

  7. Mount the nfs
    $ sudo mount -a;

    Then you can access the file on /destination/path you defined.

sources:

Previous Post Next Post

Add a comment