21.7. Practical Lab: Building a Routed File Service
The final lab assembles the chapter's parts into the shape a real deployment takes: a file server on one network, a client on another, routing and firewall policy deciding what may pass, and a VPN carrying the client that needs access from outside the trusted LAN. The service was built in earlier sections; this section builds the network around it and then verifies the result from every position - allowed, denied, and recovered.
21.7.1. Planning Client, File-Server, and Routed Network Roles
The roles are already in place from the chapter's introduction:
filesrv at 192.168.230.10 serving NFS, SMB, and DNS; client1 at
192.168.230.20 on the same LAN; fsrouter at .2 on the server LAN
and 192.168.231.2 on the remote LAN; remoteclient at
192.168.231.20 behind it. The plan is short and worth writing down
before touching anything, because every later rule will be checked
against it:
| Path | Purpose | Policy |
|---|---|---|
| client1 → filesrv (LAN) | primary service use | allow all service ports |
| remoteclient → filesrv (routed) | reachability exists; service refused | server firewall drops 2049/445; DNS allowed |
| remoteclient → filesrv (WireGuard) | authorized external use | tunnel admitted; same export/share policy as LAN |
The client hosts need routes for the far network, and the router
needs forwarding plus a forward policy that lets only the intended
traffic through. The route setup uses the temporary ip route form
from Chapter 17 - the lab guests are
expendable; a persistent deployment writes the same routes into its
network configuration backend. On remoteclient, in a root shell
($ sudo -i from john's shell):
# ip route replace 192.168.230.0/24 via 192.168.231.2 dev eth1
The command is silent; it sends the server LAN's traffic to the router, while the management default route stays untouched - this is the "specific route for practice traffic" pattern Chapter 19 used to keep administration independent of exercises. The mirror route belongs on filesrv, in its root shell, and is equally silent:
# ip route replace 192.168.231.0/24 via 192.168.230.2 dev eth1
It exists so replies to the remote LAN find their way back. Now the router. On fsrouter, in a root shell:
# printf "net.ipv4.ip_forward=1\n" > /etc/sysctl.d/90-ch21-router.conf
The redirection writes the setting file; nothing prints. Apply it and verify:
# sysctl --system
* Applying /usr/lib/sysctl.d/10-coredump-debian.conf ...
* Applying /usr/lib/sysctl.d/50-default.conf ...
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
* Applying /etc/sysctl.d/90-ch21-router.conf ...
kernel.core_pattern = core
net.ipv4.ip_forward = 1
Selected output: sysctl --system re-reads every configuration file
in order, printing one * Applying header per file and then every
setting it applied. The excerpt keeps the headers, the first setting,
and the last line - the one the new router file contributed; the
settings in between are the stock kernel defaults. The single line
that matters, checked on its own:
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
With forwarding on, the router needs its filter. The complete contents
of /etc/nftables.conf on fsrouter:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority filter; policy accept;
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related accept
iifname "eth2" oifname "eth1" ip daddr 192.168.230.10 accept
iifname "eth1" oifname "eth2" ct state established,related accept
}
chain output {
type filter hook output priority filter; policy accept;
}
}
The forward chain is the routed-policy teaching case: the remote LAN
(eth2) may reach exactly one destination - the file server - and
nothing else on the server side; replies flow back by connection
state, not by address pair. The input and output policies stay
permissive because this router's job is forwarding, not protecting
itself - management SSH to it is unaffected by any exercise. Leave the
root shell (exit) and load the ruleset as john (no output on
success) and verify - on fsrouter:
$ sudo nft -f /etc/nftables.conf
$ sudo nft list ruleset
table inet filter {
chain input {
type filter hook input priority filter; policy accept;
}
chain forward {
type filter hook forward priority filter; policy drop;
ct state established,related accept
iifname "eth2" oifname "eth1" ip daddr 192.168.230.10 accept
iifname "eth1" oifname "eth2" ct state established,related accept
}
chain output {
type filter hook output priority filter; policy accept;
}
}
The routing layer is now doing exactly one narrow thing, which is what makes the next section's failures meaningful: when remoteclient cannot reach a port, it will be because either this forward chain or the server's input chain refused it - and the tests distinguish which.
21.7.2. Combining Addressing, DNS, Firewall Policy, VPN Access, and Shares
The remote client's authorized path is a WireGuard tunnel;
Chapter 19 covered the protocol and wg-quick
in depth, so this section moves quickly through the pieces in the
file-service context. Install the tool on both tunnel endpoints - on
filesrv and on remoteclient, as john on each (apt prints its plan and
asks for confirmation on both):
$ sudo apt install wireguard-tools
Generate each side's keys in a root shell ($ sudo -i from john's
shell on each endpoint), with umask 077 so the private key file is
created private. On filesrv:
# umask 077; wg genkey > /etc/wireguard/fs.key; wg pubkey < /etc/wireguard/fs.key > /etc/wireguard/fs.pub; cat /etc/wireguard/fs.pub
b/5MCM4SfOr45smZkSg3h+yMcT2Gn9oDLDrGkRhOIG4=
Three commands in sequence: wg genkey writes a private key, wg
pubkey derives the matching public key from it, and cat prints
the public key - the value the peer needs. On remoteclient, in its
root shell:
# umask 077; wg genkey > /etc/wireguard/remote.key; wg pubkey < /etc/wireguard/remote.key > /etc/wireguard/remote.pub; cat /etc/wireguard/remote.pub
uQpxx8jnlzKszhguqiVNFOZ/qMtt0+gEK8hr8p8tQjs=
The two tunnel endpoints then describe each other. The complete
contents of /etc/wireguard/wg0.conf on filesrv:
[Interface]
Address = 10.21.0.1/24
ListenPort = 51820
PrivateKey = <contents of /etc/wireguard/fs.key>
[Peer]
PublicKey = uQpxx8jnlzKszhguqiVNFOZ/qMtt0+gEK8hr8p8tQjs=
AllowedIPs = 10.21.0.2/32
The complete contents of /etc/wireguard/wg0.conf on remoteclient:
[Interface]
Address = 10.21.0.2/24
PrivateKey = <contents of /etc/wireguard/remote.key>
[Peer]
PublicKey = b/5MCM4SfOr45smZkSg3h+yMcT2Gn9oDLDrGkRhOIG4=
Endpoint = 192.168.230.10:51820
AllowedIPs = 10.21.0.0/24
PersistentKeepalive = 25
The keys shown are the lab's disposable values; substitute the ones
your wg genkey runs produced. The structure is the
server-and-client shape from Chapter 19: the server listens on
51820 and admits exactly one peer address; the client knows the
server's endpoint, routes the tunnel network through the peer, and
sends a keepalive every 25 seconds so stateful filters along the way
keep the session alive. Leave the root shells on both endpoints
(exit on each). Bring both ends up - on filesrv, as john:
$ sudo wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.21.0.1/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
wg-quick prints each underlying command as it runs (the [#] lines
are its own narration, not a shell prompt): it created the interface,
configured the peer, assigned 10.21.0.1, and raised the link with
the 1420 MTU that leaves room for the tunnel's own overhead. On
remoteclient, as john:
$ sudo wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.21.0.2/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
Two services must now notice the new interface. Restart dnsmasq on
filesrv so its bind-dynamic configuration binds wg0 - as john:
$ sudo systemctl restart dnsmasq
The restart is silent. Verify the tunnel carries both packets and names. On remoteclient, as john:
$ ping -c 2 -W 2 10.21.0.1
PING 10.21.0.1 (10.21.0.1) 56(84) bytes of data.
64 bytes from 10.21.0.1: icmp_seq=1 ttl=64 time=0.899 ms
64 bytes from 10.21.0.1: icmp_seq=2 ttl=64 time=1.29 ms
--- 10.21.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.899/1.096/1.294/0.197 ms
The tunnel's own state is the next check - on remoteclient, as john:
$ sudo wg show
interface: wg0
public key: uQpxx8jnlzKszhguqiVNFOZ/qMtt0+gEK8hr8p8tQjs=
private key: (hidden)
listening port: 47422
peer: b/5MCM4SfOr45smZkSg3h+yMcT2Gn9oDLDrGkRhOIG4=
endpoint: 192.168.230.10:51820
allowed ips: 10.21.0.0/24
latest handshake: 7 seconds ago
transfer: 348 B received, 436 B sent
persistent keepalive: every 25 seconds
A recent latest handshake is WireGuard's proof that both ends
authenticated each other - no handshake means keys or endpoint are
wrong, and everything else fails silently after it. The lab's DNS was
planned for exactly this moment: on remoteclient, as john:
$ dig +short @10.21.0.1 files-vpn.lab.example
10.21.0.1
The server answered on its tunnel address, and the name
files-vpn.lab.example resolves there - the same dnsmasq include
from Section 21.2.3, now also bound to wg0. Now use the service
through the tunnel. Mount the team export over it - on remoteclient,
open a root shell ($ sudo -i from john's shell; the directory
creation is silent):
# mkdir -p /mnt/vpn
Leave the root shell and mount from john's shell:
$ sudo mount -t nfs4 files-vpn.lab.example:/team /mnt/vpn
The mount, like every NFSv4 mount so far, prints nothing:
$ ls /mnt/vpn >/dev/null; findmnt -no TARGET,SOURCE,FSTYPE /mnt/vpn
/mnt/vpn files-vpn.lab.example:/team nfs4
The same export, the same sec=sys semantics, over a path whose
every byte is encrypted - and it worked without touching the NFS
configuration, because the export list admitted 10.21.0.0/24 from
the start. SMB rides the same tunnel:
$ smbclient -L //files-vpn.lab.example -U john%handbook -m SMB3
Sharename Type Comment
--------- ---- -------
team Disk Team collaboration
public Disk Read-only shared files
IPC$ IPC IPC Service (Debian 13 file server)
SMB1 disabled -- no workgroup available
The share listing over the tunnel is identical to the LAN listing from
Section 21.4.2 - same shares, same account, same protocol floors -
because Samba's hosts allow admitted 10.21.0. alongside the LAN,
and the firewall admits wg0 outright. One file service, two access
paths, one policy.
21.7.3. Checking Allowed and Denied Access and Recovering a Broken Connection
The lab's plan from Section 21.7.1 promised three positions; test each from the client that occupies it. First the allowed path - on client1, as john:
$ nc -zv -w4 files.lab.example 2049
Connection to files.lab.example (192.168.230.10) 2049 port [tcp/nfs] succeeded!
The denied positions - on remoteclient, as john:
$ nc -zv -w4 files.lab.example 2049
nc: connect to files.lab.example (192.168.230.10) port 2049 (tcp) timed out: Operation now in progress
$ nc -zv -w4 files.lab.example 445
nc: connect to files.lab.example (192.168.230.10) port 445 (tcp) timed out: Operation now in progress
A timeout, not a refusal: the packets reach the server - the router
forwarded them, exactly as its rules say - and die in the server's
input chain, which has no rule for a 192.168.231.0/24 source on
those ports. That is the first layer of the plan holding. DNS, which
the server does allow from anywhere on eth1, still works from the
remote LAN:
$ dig +short @files.lab.example files.lab.example
192.168.230.10
Names resolve; service does not. The distinction is deliberate - a remote client can discover the server's address without being able to use the service, and the next test shows what happens when the firewall layer is removed and the service layers must refuse on their own.
On filesrv, load a temporary diagnostic ruleset. Make a copy of
/etc/nftables.conf and add one input rule to it - the complete
addition:
iifname "eth1" ip saddr 192.168.231.0/24 tcp dport { 2049, 445 } accept
The lab saved the copy as /tmp/nftables-filesrv-open.conf - a
throwaway diagnostic variant; the persistent policy file is untouched.
Load it - on filesrv, as john:
$ sudo nft -f /tmp/nftables-filesrv-open.conf
The load prints nothing. Now the packets arrive at the services themselves. The mount point
for the test must exist - on remoteclient, in a root shell
($ sudo -i from john's shell):
# mkdir -p /mnt/remote
Back in john's shell (exit), try NFS - on remoteclient, as john:
$ sudo mount -t nfs4 files.lab.example:/team /mnt/remote
mount.nfs4: access denied by server while mounting files.lab.example:/team
A new error, and a different layer: access denied by server is the
NFS export list refusing a client from 192.168.231.0/24 - the
firewall said yes, the export policy said no. Try SMB - on
remoteclient, as john:
$ smbclient //files.lab.example/team -U john%handbook -m SMB3 -p 445 -c "ls"
session setup failed: NT_STATUS_LOGON_FAILURE
The credentials are correct - they work over the tunnel and the LAN -
so the failure is a third layer: Samba's hosts allow rejected the
connection before authentication, and its log says so in those words -
on filesrv, as john:
$ sudo grep -h "Denied connection" /var/log/samba/log.smbd | tail -n 2
Denied connection from 192.168.231.20 (192.168.231.20)
Denied connection from 192.168.231.20 (192.168.231.20)
The pipeline searches the general log for the daemon's denial message
(-h suppresses the file-name prefix) and keeps the last two
occurrences - this section's two attempts, refused and recorded before
any authentication could even begin. Restore the strict policy - on
filesrv, as john:
$ sudo nft -f /etc/nftables.conf
Silent again, like every ruleset load. The exercise is the chapter's trust-boundary argument made literal: with the firewall open, the export list and the share policy still held, and the log recorded who tried. Three layers, each refusing in its own dialect, each independently testable.
Finally, break the authorized path and recover it - the failure a real site actually experiences. Bring the tunnel down - on remoteclient, as john:
$ sudo wg-quick down wg0
[#] ip link delete dev wg0
Now use the tunnel-mounted NFS filesystem:
$ ls /mnt/vpn
The command produces no output and does not return. The mount is a
default hard mount - Section 21.3.4's hard semantics - and the
server's address is now unreachable through the only path the mount
knows. Interrupt it with Ctrl+C, which modern kernels deliver to
processes blocked on NFS I/O. A soft mount would have returned an
I/O error after its retries, exactly as the earlier outage
demonstrated; this one waits, by design.
Restore the tunnel - on remoteclient, as john:
$ sudo wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.21.0.2/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
The hard mount recovers on its own once the path returns. The first access after the wait may pause for up to a retry interval while the NFS client re-establishes its connection, and then the mount answers normally again:
$ ls /mnt/vpn >/dev/null; findmnt -no TARGET,SOURCE /mnt/vpn
/mnt/vpn files-vpn.lab.example:/team
The recovery recipe is therefore: restore the path, then verify. No
remount was needed because the server never restarted - its file
handles stayed valid, so the mount that blocked through the outage
simply answered again. Had the server itself restarted or the export
been redefined, the umount/mount pair from Section 21.3.4 would be
the recipe instead. In production the same analysis covers a VPN
gateway reboot, a WAN outage, or any interruption of an off-LAN
client's only route - and the monitoring of Section 21.6.4 is what
tells the administrator which clients are sitting in that silent
hard-mount wait right now.
The lab's final state is worth one deliberate look, because it is the
shape being handed to operations: the exports admit the LAN and the
tunnel (exportfs -v shows both client groups per export), the Samba
policy admits the same two networks, the server's nftables ruleset
admits exactly those paths plus DNS and the tunnel's own UDP port,
and every credential that crosses the boundary - the WireGuard keys,
john's SMB password - is a per-service secret rather than a shared
network trust. That is the whole chapter in one sentence: storage made
into a service, and trust made explicit at every layer the traffic
crosses.