tuxvador@blog:~/blog/homelab-network-segmentation$

~/blog/homelab-network-segmentation

Segmenting a Flat Homelab in Three Layers

4 min readLire en français →

#security#networking#proxmox#headscale#homelab

Ever since I wrote it, the “What’s next” list in my infrastructure overview has listed “proper inter-container firewall rules”. A short exposure audit made it urgent. From the internet, only ports 80/443 and the WireGuard port reached home, and that part was fine. Inside, everything reached everything:

  • The tailnet had no ACL. Headscale’s policy.path was empty, which means allow-all. With the subnet route to the containers, every node could reach SSH on every container, and the hypervisor’s GUI. That included the internet-facing public server and the living-room TV.
  • The hypervisor had no firewall. Any device on the home LAN reached its SSH, rpcbind and web GUI, and could route to the container subnet through it.
  • Only one container dropped by default. The others accepted any connection. A compromised media server (torrents, a public web app) or the reverse proxy (internet-facing) could SSH sideways to its neighbours.

Each path needs a different tool, so the fix was three layers.

Rolling out a firewall without locking yourself out

All three layers changed something I was connected through. Each change went in with a dead-man switch: a timer that undoes it unless I cancel the timer.

systemd-run --on-active=240 --unit=fw-revert nft delete table inet homelab_fw
nft -f /etc/homelab-fw.nft
# ... check admin access, public sites, monitoring, agents, DNS ...
systemctl stop fw-revert.timer      # keep it

If the new rules cut me off, they disappear four minutes later. I applied one host at a time and checked everything after each: SSH from the admin machines, every public site, the uptime monitors, the Wazuh agents, WiFi DNS and internet, the tailnet.

Before enforcing anything I ran each rule set in log-only mode for ten minutes and wrote the allow-list from what was actually observed, not from what I remembered. That’s how I found that the TV’s streaming app talks to the media server over the tailnet. I still forgot to carry it into the first ACL version, and the app was blocked for fifteen minutes.

Layer 1: the tailnet ACL

Tailnet traffic reaches the containers through the VPN container, which masquerades it. Every tailnet device therefore shows up as the same source address to the containers. Container firewalls can’t tell the TV from my laptop, so per-device rules have to live in the ACL. Headscale reads a HuJSON policy, deny by default:

{
  "hosts": {
    "laptop": "100.64.0.21", "dev-box": "100.64.0.22", "phone": "100.64.0.23",
    "mail-srv": "100.64.0.24", "tv": "100.64.0.25",
    "mon-srv": "10.99.99.10", "soc-srv": "10.99.99.15", "media-srv": "10.99.99.13"
  },
  "acls": [
    { "action": "accept", "src": ["laptop", "dev-box", "phone"], "dst": ["*:*"] },
    { "action": "accept", "src": ["mail-srv"], "dst": ["mon-srv:514,8080", "soc-srv:1514,1515"] },
    { "action": "accept", "src": ["tv"], "dst": ["media-srv:8080,8091"] }
  ]
}

The admin devices reach everything. The public server reaches exactly four ports: syslog, the CrowdSec API, and Wazuh’s two. The TV reaches the media server’s app ports. The exit node and the VPN container itself reach nothing. A new node reaches nothing until it’s added here.

headscale policy check --file acl.hujson validates it before a reload. To test reach from a node, use ping: Tailscale only answers ICMP to addresses the policy opens.

Layer 2: the hypervisor’s LAN side

Proxmox has its own firewall, but I wanted something small enough to read in one go. It’s a oneshot service that loads two iptables chains, applied only to traffic arriving on the LAN bridge:

  • FORWARD, LAN to containers: replies and the port forwards (80/443 to the proxy, WireGuard to the VPN container). Everything else is logged and dropped.
  • INPUT, LAN to the hypervisor: SSH, the GUI and the monitoring port, only from the dev laptop. That’s a break-glass path that doesn’t depend on the VPN.

The container bridge, container egress and the NAT rules were left alone. rpcbind was disabled while I was there: no NFS storage, no reason for it to listen.

Layer 3: default-drop in every container

Each container gets the same nftables table, generated by one script from a per-host list:

table inet homelab_fw {
  chain input {
    type filter hook input priority 0; policy drop;
    iif lo accept
    ct state established,related accept
    meta l4proto { icmp, ipv6-icmp } accept
    ip saddr { 10.99.99.1, 10.99.99.10, 10.99.99.25 } accept   # hypervisor, monitoring, tailnet
    # host-specific lines below
  }
}

The admin plane (hypervisor, monitoring container, and tailnet traffic, which the ACL has already filtered) gets every port. The rest is per host:

Host Also open
dhcp-srv 67/udp
web-proxy 80, 443 from anywhere
media-srv app ports from the proxy only; its Docker bridges
soc-srv 1514/1515 from the container subnet (agents), 443 from the proxy
vpn-srv the TLS fronts from the proxy, WireGuard/Tailscale UDP
wifi-ap DNS and DHCP on the WiFi bridge only

The table loads from its own service, ordered after nftables.service and PartOf it. Most of these containers have an /etc/nftables.conf that starts with flush ruleset. Without the PartOf, a restart of nftables would quietly drop my table.

The test that mattered: from the media server, the reverse proxy and the DHCP server, SSH to a neighbour is now refused.

What it cost

One ACL file, one iptables script, one generator for six container rule sets, and about an evening, mostly spent checking. Nothing user-visible broke apart from the TV’s fifteen minutes. The rule that keeps it maintainable: a new service port that a non-admin host needs is a line in the generator, and a new tailnet node is a line in the ACL.

Pitfalls

  • An empty Headscale policy.path means allow-all, not deny-all.
  • Masqueraded tailnet traffic all looks like one address to the containers. Per-device rules belong in the ACL.
  • Write the allow-list from observed flows. Ten minutes of logging found a flow I didn’t know existed, and I still lost it once while copying.
  • Use a dead-man switch. A timer that reverts the rules turns a lockout into a four-minute wait.
  • flush ruleset in /etc/nftables.conf wipes tables that other services loaded. Tie your table’s service to nftables with PartOf.
  • Stale persistence files lie. The hypervisor still has an iptables/rules.v4 from July with rules that aren’t live. It doesn’t matter today, but it will after the wrong reboot.

cd ~/blog