NFS - Network File System

In a closed network (where you know every device), NFS is a fine choice. With a good network, throughput it disgustingly fast and at the same time less CPU intensive on the server. It’s very simple to set up and you can toggle readonly on shares you don’t need to be writeable. - NFS vs Samba

Symbolic links only contain a path to another file or directory on the originating system where they’re being shared from. Unless you take care to make the links relative or to duplicate the same directory structures on remote systems as the originator of the share, they simply will not work.

This can be easily fixed: see symlink

Client

List exporter folder for given server

showmount -e [server ip]

Mount Shared Directory

$ sudo mkdir -p /nfs/backup
$ sudo mount 192.168.0.125:/mnt/Backup /nfs/backup

Auto-mounting an NFS share

Automount (systemd)

The main difference is that autofs, with the right auto scripts, will dynamically list the available shares. So you don’t need to pre-define and hard-code which machines/shares should be made available.

With systemd’s automount, only shares which you have pre-configured will be visible.

Install

$ sudo apt install nfs-common

Autofs

$ sudo apt-get install autofs

Add the following line at the end of /etc/auto.master

/nfs   /etc/auto.nfs	--ghost,--timeout=30

Create /etc/auto.nfs, and specify nfs mount options:

<server-name>   -fstype=nfs4,soft   <server-ip/host>:/

Reload /etc/init.d/autofs

$ systemctl start autofs

Host

Creating the Exported Directories on the Host

sudo micro /etc/exports

directory_to_share    client(share_option1,...,share_optionN)

Then restart service: sudo systemctl restart nfs-kernel-server

Options details

rw: This option gives the client computer both read and write access to the volume.

sync: This option forces NFS to write changes to disk before replying. This results in a more stable and consistent environment since the reply reflects the actual state of the remote volume. However, it also reduces the speed of file operations.

no_subtree_check: This option prevents subtree checking, which is a process where the host must check whether the file is actually still available in the exported tree for every request. This can cause many problems when a file is renamed while the client has it opened. In almost all cases, it is better to disable subtree checking.

no_root_squash: By default, NFS translates requests from a root user remotely into a non-privileged user on the server. This was intended as security feature to prevent a root account on the client from using the file system of the host as root. no_root_squash disables this behavior for certain shares.

Refs

see also

Written on May 10, 2019, Last update on June 24, 2024
nfs samba linux-system client server filesystem