Filesystem Types mentions NFS and CIFS/SMB as network filesystem types; this covers actually setting one up, not just mounting an already-configured share.

Which one to use

NFS is simpler and faster between Linux/Unix machines, but assumes a fairly trusted network (its traditional authentication model is host-based, not user/password) and has no native Windows client. Samba implements the SMB/CIFS protocol, interoperating natively with Windows and macOS, with proper username/password authentication - the right choice the moment a share needs to reach anything other than Linux clients.

NFS: server setup

sudo apt install nfs-kernel-server   # Debian/Ubuntu
sudo dnf install nfs-utils            # Fedora/RHEL

Define what to share and who can access it in /etc/exports:

/srv/shared  192.168.1.0/24(rw,sync,no_subtree_check)
Option Meaning
rw Read-write (vs. ro, read-only)
sync Confirm writes to disk before acknowledging them (safer, slower than async)
no_subtree_check Skip an extra consistency check most modern setups don't need
sudo exportfs -ra                # re-read /etc/exports without a full restart
sudo systemctl enable --now nfs-kernel-server

NFS: client mount

sudo mount -t nfs 192.168.1.10:/srv/shared /mnt/shared

For a mount that should persist, add it to /etc/fstab (see Mounting and fstab) the same as a local filesystem, just with a server address instead of a device path:

192.168.1.10:/srv/shared  /mnt/shared  nfs  defaults  0  0

Samba: server setup

sudo apt install samba

Define a share in /etc/samba/smb.conf:

[shared]
    path = /srv/shared
    browseable = yes
    read only = no
    valid users = alice

Samba users are separate from Linux system accounts and need their own password set:

sudo smbpasswd -a alice
sudo systemctl enable --now smbd

Samba: client access

sudo mount -t cifs //192.168.1.10/shared /mnt/shared -o username=alice
smbclient //192.168.1.10/shared -U alice     # interactive FTP-like browser, no mount needed

A persistent /etc/fstab entry works the same way as NFS, with credentials usually kept in a separate, permission-restricted file rather than inline in fstab itself:

//192.168.1.10/shared  /mnt/shared  cifs  credentials=/etc/samba/creds,uid=1000  0  0
# /etc/samba/creds, chmod 600
username=alice
password=hunter2

Firewall considerations

Both need specific ports opened - NFS uses a cluster of ports (historically dynamic via rpcbind, though NFSv4 consolidates to a single port 2049), Samba needs 139 and 445:

sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw allow from 192.168.1.0/24 to any port 139,445 proto tcp

(nfs resolves via /etc/services; Samba has no equivalent named service entry, so its two ports - netbios-ssn and microsoft-ds - need to be given explicitly.)

Scope both to the trusted local network specifically rather than opening them broadly - see Firewalls: iptables and nftables. Neither protocol is designed to be exposed to the open internet directly; reach a share remotely through a VPN (see VPN Basics with WireGuard) or an SSH tunnel instead.