Chapter 21. Network File Sharing

A file server turns storage into a service: many machines use the same files through one exported tree, and the administrator decides who may read, who may write, and from where. Debian carries two mature protocols for this. NFS speaks the native language of Unix systems - numeric owners, POSIX permissions, hard mounts that behave like local disks. SMB speaks the language of mixed environments - authenticated user accounts, Windows-compatible semantics, encryption negotiated in the protocol itself. Most real file servers end up speaking both, because the clients demand it.

This chapter builds one file server and drives it from two client positions. The server exports a small tree over NFSv4, publishes the same directories through Samba as SMB shares, and enforces its policy in layers: export lists and share definitions say who may connect, nftables rules say which networks may reach the service at all, and a VPN carries the one client that is not on a trusted LAN. Along the way it covers the parts that actually break in practice - identity mapping, stale file handles, protocol negotiation failures, quota overflow - and closes with the operational habits that keep a file service healthy: capacity watching, backup verification, and a tested restore.

The four Debian 13 machines and their addresses:

Host Role Practice interfaces Administration
filesrv the file server: NFSv4, Samba, lab DNS eth1 - server LAN, 192.168.230.10/24; data disk /dev/vdb at /srv/nfs eth0 - management network, 192.168.121.0/24
client1 LAN client for NFS and SMB eth1 - server LAN, 192.168.230.20/24 eth0 - management network
fsrouter router between the two practice LANs eth1 - server LAN, 192.168.230.2/24; eth2 - remote LAN, 192.168.231.2/24 eth0 - management network
remoteclient client behind the router; reaches the server through a WireGuard tunnel eth1 - remote LAN, 192.168.231.20/24 eth0 - management network

The chapter 21 practice network

Figure 21.1. Two isolated practice LANs, a router between them, and a WireGuard tunnel that gives remoteclient an authenticated path to the same NFS and SMB services client1 uses directly. The management network carries SSH and updates but no exercise traffic.

The management network is deliberate insurance: every disruptive exercise in this chapter runs on eth1, eth2, or the tunnel, so a mistake in a share definition or a firewall rule cannot cost administrative access. That is the same arrangement a production site builds with a separate management VLAN, and Chapter 18 and Chapter 19 built the filtering and routing vocabulary this chapter reuses.

Commands entered in john's ordinary shell begin with $ and commands entered in a root shell begin with #; the prompt marker is not typed. Single elevated steps are written $ sudo command, which asks for john's password the first time in a session (the password is not echoed). Sustained server-side work opens a root shell with $ sudo -i - the prompt changes, HOME becomes /root, and exit leaves the shell. john holds administrative rights through the sudo delegation of Chapter 5; if your site delegates differently, adapt the elevated commands to its method. Before each command block the text names the target host and the shell it runs in.

Every host carries the same two human accounts, with identical UID and GID values on all four machines: john (UID 2100, primary group john, GID 2100) is the reader account with sudo rights, and alice (UID 2101, primary group alice) exists so group collaboration and denial checks have a second real person. The group team (GID 2105) holds both and backs the collaboration share. The lab uses handbook as the password for both accounts, for login and later for the Samba password database; replace it with your own values. On each host used as a client, john works in a named workspace:

$ mkdir -p ~/debian-handbook/network-files

The command prints nothing on success. Make ~/debian-handbook/network-files the working directory with cd ~/debian-handbook/network-files when a step produces files.

The captures in this chapter come from Debian 13.5, kernel 6.12.86+deb13-amd64, with the package versions below. Sections install these packages as they reach them; the inventory is the complete server-side set once every section has run. On filesrv, open a root shell and check:

# dpkg-query -W nfs-kernel-server nfs-common samba samba-common-bin quota acl attr rsync nftables wireguard-tools dnsmasq
acl 2.3.2-2+b1
attr    1:2.5.2-3
dnsmasq 2.91-1+deb13u2
nfs-common  1:2.8.3-1
nfs-kernel-server   1:2.8.3-1
nftables    1.1.3-1
quota   4.09-1+b1
rsync   3.5.0+ds1-0+deb13u2
samba   2:4.22.11+dfsg-0+deb13u1
samba-common-bin    2:4.22.11+dfsg-0+deb13u1
wireguard-tools 1.0.20210914-3
# uname -r
6.12.86+deb13-amd64
# cat /etc/debian_version
13.5

Leave the root shell with exit; the rest of the chapter says when to open one again. Names in Chapter 17 and Chapter 20 cover how these hosts got their interfaces and how john reaches them; the desktop side of SMB appears in Chapter 4.

In this section