INFRASTRUCTURE & SECURITY // HOMELAB DEFENCE

WireGuard topology & homelab isolation

Designing a private network architecture on a VPS: how I run dozens of containers, data sync and admin dashboards without opening a single management port to the public internet.

Zero Exposed Ports WireGuard Noise IK Kernel Overlay (wg0) CrowdSec IPS ~14 min read
Davito @davito_03 // David
October 2026 Level: intermediate – advanced Lab: VPS Netfilter hardening
Table of contents

01. The VPS homelab paradox

Running a virtual private server (VPS) around the clock is the cornerstone of any modern self-hosting setup: symmetric bandwidth that home ISPs don't throttle, 24/7 availability and a fixed or managed IP address. But the moment you deploy your first monitoring container, download manager or database, a major security dilemma appears:

The opportunistic exposure trap
How do you work with dozens of admin web interfaces from a workstation, laptop or phone without exposing management ports to mass scans from Shodan, Censys and automated botnets?

The intuitive (and dangerous) answer from less experienced admins is to publish arbitrary ports in the firewall: 3001 for Uptime Kuma, 8091 for Beszel, 8384 for Syncthing, 9000 for Portainer or 8080 for internal microservices. That turns the server into an easy target:

  • Indexed and catalogued within minutes: infrastructure search engines (Shodan, Censys, Project Sonar) sweep the entire IPv4 space every day. Their crawlers record HTML titles, exact HTTP library versions and self-signed TLS certificates.
  • A polymorphic attack surface: every web container brings its own runtime (Node.js/Express, Python/FastAPI, Go HTTP, Rust/Actix). A buffer overflow, SQL injection or container escape in any of them compromises the host.
  • Logs flooded by dictionary attacks: brute-force bots try default credentials (admin/admin, root/root) non-stop, eating bandwidth and filling gigabytes of logs with useless noise.

To remove this attack vector without giving up access, my infrastructure follows one unbreakable rule: zero exposed management ports. All control traffic is wrapped in a virtual overlay mesh run by the WireGuard cryptographic protocol.

02. WireGuard & the Noise IK cryptographic handshake

Unlike legacy suites such as OpenVPN or IPsec (which carry more than 100,000 lines of user-space code, complex PKI hierarchies with X.509 certificates and slow context switches), WireGuard was designed from the ground up to run in Linux kernel space (wireguard.ko), in fewer than 4,000 auditable lines of code.

WireGuard's engine implements the Noise Protocol Framework, specifically the Noise_IKpsk2 pattern:

Primitive Algorithm Role in the tunnel
Key exchange Curve25519 (ECDH) 256-bit elliptic-curve Diffie-Hellman to derive session secrets in a single round trip (1-RTT).
Symmetric encryption ChaCha20 A high-speed stream cipher that is immune to cache-timing attacks.
Authentication (MAC) Poly1305 A one-time message authentication code to strictly verify integrity.
Hash function & KDF BLAKE2s Derives transport keys and computes anti-DoS cookie tokens.
Anti-replay protection Sliding window (64-bit) A packet counter with a sliding window that neutralises replay attacks.

The “network silence” principle (stealth)

One of WireGuard's most impressive traits is how it reacts to outside probes. When a scanner such as Nmap sends arbitrary UDP packets to the VPS's port:

  1. The kernel computes the MAC1 cryptographic signature using the public key registered on the wg0 interface.
  2. If the packet doesn't carry a valid signature or the peer's key isn't in the AllowedIPs list, the kernel simply drops the packet silently.
  3. No ICMP Port Unreachable reply or TCP RST packet is sent back.
Invisible to Shodan
To any port scanner on the internet, WireGuard's UDP port looks exactly like an IP address that doesn't exist or a host that's switched off. No information leaks and no readable banners.

03. Hub-and-spoke topology & packet flow

The network uses a segmented hub-and-spoke layout. The VPS acts as the central hub, while workstations, mobile devices and touchscreens are satellite nodes (spokes).

Level 1: authenticated satellite nodes (spokes)
Main PC
10.66.66.2/32
Linux / Windows development workstation. SSH access and dashboards.
Curve25519 peer
Personal phone
10.66.66.3/32
Smartphone with WireGuard always-on / on-demand.
Curve25519 peer
Remote laptop
10.66.66.4/32
Portable device for admin emergencies away from the LAN.
Curve25519 peer
MT6580 tablet
10.66.66.5/32
Recovered kiosk dashboard running Android 8.1 with ZRAM tuning.
WireGuard Go
Encrypted UDP tunnel (Noise IK handshake · cryptographic 1-RTT)
Level 2: central gateway (wg0 hub · Linux kernel)
wg0 interface (10.66.66.1/24) · cryptokey routing table
Netfilter: direct routing between clients and local microservices, with no unnecessary NAT
The kernel tables bind each 10.66.66.X source IP strictly to its registered public key. Any spoofing attempt is dropped at the root.
Loopback isolation and interface-only sockets
Level 3: hardened containers & services (zero exposure)
Beszel Hub
127.0.0.1:8091
CPU, RAM, disk and temperature telemetry.
Uptime Kuma
127.0.0.1:3001
Internal health monitoring for the microservices.
Syncthing BEP
10.66.66.1:22000
Direct TLS 1.3 replication with no discovery relays.
SearXNG proxy
10.66.66.1:8444
Private metasearch engine with internal TLS.

04. Docker & the 0.0.0.0 trap (Netfilter / iptables bypass)

This is one of the most widespread misconfigurations in the self-hosting community. Many people set up ufw rules assuming their server is protected by a default-deny policy:

THE FALSE SENSE OF SECURITY (UFW)
# El usuario ejecuta:
$ sudo ufw default deny incoming
$ sudo ufw allow 22/tcp
$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp
$ sudo ufw enable

# ...pero luego en su docker-compose.yml escribe:
ports:
  - "3001:3001"  # <--- ¡BRECHA CRÍTICA! Bindea en 0.0.0.0
Why doesn't UFW stop Docker?
By default, the Docker daemon directly manipulates the PREROUTING and DOCKER tables in iptables. Docker's rules are evaluated before the packet reaches the INPUT chain managed by UFW. As a result, port 3001 is exposed on the VPS's public IP, completely overriding UFW's deny incoming rule.

The fix: explicit hardened binding

To stop Docker from injecting public rules into PREROUTING, I always pin the binding IP for every service:

  • Bind to loopback (127.0.0.1): the port is only reachable by processes on the host (such as nginx acting as a local reverse proxy).
  • Bind to WireGuard (10.66.66.1): the port only handles packets that have already been authenticated and decrypted by the kernel's virtual interface.
docker-compose.yml // hardened port mapping
# Configuración segura: ningun servicio escucha en 0.0.0.0
services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    restart: unless-stopped
    ports:
      # Solo accesible mediante el proxy local Nginx
      - "127.0.0.1:3001:3001"
    volumes:
      - ./kuma-data:/app/data

  searxng-proxy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      # Solo accesible para clientes autenticados en la VPN wg0
      - "10.66.66.1:8444:8444"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile

05. Two nginx zones: public gateways vs. VPN gateways

In this defence-in-depth model, the nginx web server works as a smart router split into two strictly sealed zones:

Zone A: the public realm (edge & proxied CDN)

Public-facing services such as davito.es, davito.dev or status.davito.dev. They have:

  • Reverse DNS proxy with DDoS mitigation and Cloudflare Full (Strict) encryption.
  • HSTS headers with max-age=63072000; includeSubDomains; preload.
  • A Content Security Policy (CSP) that blocks unauthorised external resources.
  • Brotli and gzip compression for the fastest response times.

Zone B: the private realm (VPN server blocks on 10.66.66.1)

Tools such as Stirling PDF, the hardware telemetry dashboard, IT-Tools or admin interfaces. They have no public Cloudflare subdomain and no public DNS record at all. Their server blocks listen exclusively on the tunnel IP:

/etc/nginx/conf.d/vpn-services.conf
# Servidor Nginx accesible ÚNICAMENTE dentro de la VPN
server {
    # Escucha estricta en el socket de la interfaz virtual wg0
    listen 10.66.66.1:8181 ssl;
    server_name 10.66.66.1;

    ssl_certificate     /etc/ssl/internal/fullchain.pem;
    ssl_certificate_key /etc/ssl/internal/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    location / {
        # Proxy pass al contenedor local en loopback
        proxy_pass http://127.0.0.1:8181;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;

        # Soporte para WebSockets (dashboards interactivos)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

If a TCP packet tries to reach port 8181 on the server's public IP, the kernel socket answers with an RST or drops it immediately, before nginx processes a single byte of the HTTP request.

06. Active mitigation with CrowdSec IPS & nftables at wire speed

Even with management ports fully locked down, the public web ports (80 and 443) have to stay open to serve production apps. A static firewall isn't enough against persistent vulnerability scans (LFI, SQLi, hunting for .env or wp-login.php files).

To handle that, a CrowdSec agent stands guard as an intrusion prevention system (IPS):

  • Multi-source telemetry: CrowdSec parses /var/log/nginx/access.log, SSH authentication logs (/var/log/auth.log) and Docker container output as a stream.
  • Heuristic detection scenarios: rules such as crowdsecurity/http-crawl-non_statics, crowdsecurity/http-sensitive-files and crowdsecurity/ssh-bf detect distributed attacks within milliseconds.
  • Remediation with the nftables bouncer: when a ban is issued, the bouncer adds the attacking IP to a dynamic kernel set (nft set).
Wire-speed performance
Because it works directly inside kernel-level nftables sets, packets from malicious IPs are dropped (DROP) with O(1) algorithmic complexity before they use any CPU cycles in user space.

07. Case study: Obsidian vault & Syncthing BEP over TLS 1.3

The most demanding test for this topology is my personal knowledge base and technical documentation (an Obsidian vault called La Cúpula). It holds thousands of Markdown files, database schemas, diagrams and research notes, synced in real time between my workstation, my phone and the VPS.

Syncing runs on Syncthing's Block Exchange Protocol (BEP), configured for maximum isolation:

Syncthing peer config // direct WireGuard peering
<!-- Ajustes estrictos de sincronización privada en Syncthing -->
<options>
    <globalAnnounceEnabled>false</globalAnnounceEnabled>
    <localAnnounceEnabled>false</localAnnounceEnabled>
    <relaysEnabled>false</relaysEnabled>
    <natEnabled>false</natEnabled>
</options>

<device id="VPS-NODE-ID" name="VPS-Core">
    <!-- Dirección estática forzada dentro del túnel wg0 -->
    <address>tcp://10.66.66.1:22000</address>
</device>

Direct benefits of this design:

  1. No leaks to discovery servers: with Global Discovery and Relaying turned off, the device's unique ID is never announced on public third-party relay servers on the internet.
  2. Encrypted block transfers: BEP splits each file into blocks of 128 KiB to 16 MiB and computes SHA-256 integrity hashes. Data travels doubly wrapped (Syncthing's native TLS 1.3 inside WireGuard's ChaCha20-Poly1305 tunnel).
  3. Instant sync on the go: when I edit a note in the Obsidian app on my phone, the WireGuard tunnel sends the changes to the VPS within about 50 milliseconds, confirmed instantly.

08. MTU clamping (1420 bytes) & keepalive tuning

One of the trickiest problems with mobile VPNs is the slowdown caused by TCP/IP packet fragmentation. When a packet exceeds the maximum transmission unit (MTU) of the underlying physical network, routers along the way have to split it into fragments, which multiplies latency, or drop it if the Don't Fragment (DF) bit is set.

Calculating the encapsulation overhead

On a standard Ethernet connection the base MTU is 1500 bytes. WireGuard adds these headers to every encapsulated packet:

  • IPv4 header: 20 bytes (or 40 bytes on IPv6).
  • UDP header: 8 bytes.
  • WireGuard header: 32 bytes (message type: 4 B, receiver index: 4 B, anti-replay counter: 8 B, Poly1305 MAC: 16 B).
  • Total overhead: 60 bytes on IPv4 / 80 bytes on IPv6.
WireGuard MTU formula
MTU_Túnel = MTU_Físico (1500) - Overhead_IPv6 (80) = 1420 bytes

Setting MTU = 1420 on the virtual interface guarantees full compatibility with 4G/5G mobile networks (which usually run MTUs of 1420 to 1440 because of GTP encapsulation) and fibre connections over PPPoE (MTU 1492), avoiding fragmentation and reassembly delays in the kernel.

Keeping state behind CGNAT: PersistentKeepalive

Mobile carriers put smartphones behind CGNAT firewalls with very aggressive NAT state timeouts (sometimes dropping UDP mappings after 30 seconds of inactivity). To work around this and keep the tunnel ready for incoming push events without draining the battery:

wg0-client.conf // mobile keepalive tuning
[Interface]
PrivateKey = a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v=
Address = 10.66.66.3/32
DNS = 10.66.66.1
MTU = 1420

[Peer]
PublicKey = z9y8x7w6v5u4t3s2r1q0p9o8n7m6l5k4j3h2g1f0e9d=
Endpoint = vpn.tu-dominio.com:51820
AllowedIPs = 10.66.66.0/24
# Envía un pulso mínimo cifrado cada 25 segundos para conservar el mapeo en CGNAT
PersistentKeepalive = 25

09. Audit routine: checking from the terminal

To make sure no unnoticed container update or system reboot has misaligned the sockets, I run a routine validation using native commands:

audit-network-ports.sh // socket leak detection
# 1. Comprobar todos los sockets TCP/UDP escuchando en interfaces públicas
# Salida esperada: ÚNICAMENTE SSH (puerto administrativo), HTTP (80) y HTTPS (443)
$ sudo ss -tulpn | grep LISTEN | grep -v '127.0.0.1\|10.66.66.1\|::1'

# 2. Inspeccionar el estado de la malla y últimos handshakes de peers
$ sudo wg show wg0
# peer: PC-Principal
#   endpoint: 198.51.100.42:58210
#   latest handshake: 14 seconds ago
#   transfer: 2.14 GiB received, 8.42 GiB sent

# 3. Comprobar decisiones activas de baneo en el motor CrowdSec
$ sudo cscli decisions list
# +------+----------+-------------------+----------------------+--------+
# |  ID  | Source   | Scope:Value       | Reason               | Action |
# +------+----------+-------------------+----------------------+--------+
# | 1402 | crowdsec | Ip:203.0.113.88   | http-sensitive-files | ban    |
# +------+----------+-------------------+----------------------+--------+

10. Conclusions and zero-trust golden rules

Real security in a homelab doesn't come from one magic tool, but from defence in depth built from complementary layers:

  1. Minimum exposure: if a service doesn't need to be used by the general public, there's no technical reason for it to listen on 0.0.0.0.
  2. Deterministic crypto-routing: WireGuard handles routing and authentication in one go with static key pairs, removing the complexity and weakness of poor passwords.
  3. Strict decoupling in Docker: always use 127.0.0.1:PORT:PORT or 10.66.66.1:PORT:PORT to neutralise the automatic iptables bypass.
  4. Active mitigation in the kernel: with CrowdSec and nftables, opportunistic attackers are stopped at the network-card level without using CPU on the server.
The result in practice
A homelab with more than 30 running containers, instant note sync and real-time monitoring, running with the peace of mind that 95% of the infrastructure is mathematically invisible to the rest of the planet.
Previous: Rooting the MT6580 tablet (eMMC & forensics) Next: Davusic (Tauri 2 & Rust)