Konstas.Engineering Notes
Networking · Cybersecurity · Infrastructure
Architecture

Layered Security Stack

Articles · 2026 · Ioannis (John) Konstas

A privacy-first, full-tunnel architecture combining WireGuard, encrypted DNS, network IDS, and SIEM โ€” deployed on a client/server model.

WireGuard Snort IDS Wazuh SIEM dnscrypt-proxy iptables fail2ban Cloudflare Tunnel OSSEC

๐Ÿ—บArchitecture Overview

Full-tunnel VPN exit node with layered defense โ€” IDS, SIEM, encrypted DNS, and blocklists.

network-topology ยท layered-security-stack
Client Machine
๐Ÿ”
WireGuardFull Tunnel ยท 0.0.0.0/0
๐Ÿ“Š
Wazuh AgentSIEM ยท FIM ยท Events
๐Ÿ‘
Snort IDSPassive ยท local tap
๐Ÿ 
OSSEC AgentHIDS ยท auth logs
โ˜๏ธ
cloudflaredQUIC ยท no open ports
UDP ยท ChaCha20-Poly1305 ยท port 51820 ยท PersistentKeepalive 25s
โ–ผ
VPS / Exit Node ยท 203.0.113.x
๐Ÿ”
WireGuard Server:51820 ยท VPN endpoint
๐ŸŒ
dnscrypt-proxyDoH ยท :53 ยท VPN only
๐Ÿ‘
Snort IDSWAN + VPN taps
๐Ÿงฑ
iptables + ipsetNAT ยท 1,800+ blocks
๐Ÿšซ
fail2banSSH guard ยท auto-ban
๐Ÿ“Š
Wazuh ManagerCorrelation ยท alerts
๐Ÿ”’
nginxTLS 1.2/1.3 ยท HSTS
NAT MASQUERADE ยท iptables POSTROUTING ยท client IP hidden
โ–ผ
Internet
๐ŸŒ
Public InternetExit IP = VPS ยท real IP hidden
๐Ÿ”’
Cloudflare EdgeDDoS ยท WAF ยท TLS
๐Ÿ›ก
Threat FeedsFeodo ยท ET ยท Tor ยท daily

โš™๏ธStack Components

Each layer has a specific responsibility. Defense in depth โ€” no single point of failure.

๐Ÿ”

WireGuard VPN

Full-tunnel client/server. All traffic โ€” IPv4 and IPv6 โ€” encrypted and routed through the VPS. Client real IP never reaches the destination.

ChaCha20-Poly1305 ยท UDP ยท AllowedIPs 0/0
๐ŸŒ

dnscrypt-proxy

DNS-over-HTTPS server running on the VPS, served only to VPN clients. All DNS queries are encrypted inside the tunnel before leaving the VPS.

DoH ยท 1.1.1.1 ยท 9.9.9.9 ยท no plain-text DNS
๐Ÿ‘

Snort IDS

Passive packet inspection on WAN, VPN, and container interfaces. Custom rules detect SSH brute force, web shells, SQLi, path traversal, and recon.

SID 9000001โ€“9000008 ยท fast alert mode
๐Ÿ“Š

Wazuh SIEM

Centralized log and event collection. Agent on client ships FIM alerts, vulnerability data, and auth events to the manager for correlation and alerting.

FIM ยท Vuln detection ยท Active response
๐Ÿ 

OSSEC

Host-based IDS running alongside Wazuh. Monitors system files, auth logs, and processes. Active response can ban IPs or kill processes on detection.

HIDS ยท log analysis ยท file integrity
๐Ÿงฑ

iptables + ipset

NAT masquerade for VPN forwarding. ipset blocklists updated daily from Feodo, Emerging Threats, and Tor exit feeds. Zero-downtime atomic swaps.

ipset hash:ip ยท 1,800+ blocked IPs
๐Ÿšซ

fail2ban

SSH brute-force protection. Monitors auth logs and inserts iptables DROP rules after N failed attempts. Automatically expires bans.

sshd jail ยท iptables ยท auto-expire
โ˜๏ธ

Cloudflare Tunnel

Exposes internal web services without opening any inbound ports. Traffic arrives encrypted from Cloudflare's edge โ€” no public IP exposure of origin.

QUIC/H2 ยท zero open ports ยท DDoS shielded

๐Ÿ”„Network Flows

How traffic moves through each path in the stack.

FLOW 1 โ€” Full Tunnel (all outbound)
CLIENT
  โ”‚ AllowedIPs = 0.0.0.0/0, ::/0
  โ”‚ ALL traffic enters tunnel
  โ”‚
  โ”‚โ”€โ”€โ–บ UDP encrypted โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ VPS:51820
  โ”‚    ChaCha20-Poly1305         โ”‚
  โ”‚    PersistentKeepalive=25s   โ”‚
  โ”‚                             โ–ผ
  โ”‚                  iptables FORWARD (pos 1)
  โ”‚                  NAT POSTROUTING MASQUERADE
  โ”‚                             โ”‚
  โ”‚โ—„โ”€โ”€ return traffic โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚
  โ”‚                             โ–ผ
  โ”‚                        INTERNET
  โ”‚
  โ””โ”€โ”€ Your visible IP = VPS IP โœ“
      Real IP = hidden โœ“
FLOW 2 โ€” DNS (encrypted, no leaks)
Client app queries DNS
  โ””โ”€โ–บ OS stub resolver
        โ””โ”€โ–บ VPN_SERVER:53
            (inside encrypted tunnel)
              โ””โ”€โ–บ dnscrypt-proxy
                    โ”‚
                    โ”œโ”€โ–บ 1.1.1.1 over HTTPS
                    โ””โ”€โ–บ 9.9.9.9 over HTTPS

DNS never leaves tunnel unencrypted.
DNS server only reachable via VPN.

Verify:
  dig google.com | grep SERVER
  โ†’ should show VPN server IP
FLOW 3 โ€” Inbound Web (Cloudflare)
Browser
  โ””โ”€โ–บ Cloudflare Edge
        โ”‚  TLS termination
        โ”‚  DDoS / bot filtering
        โ”‚
        โ”‚  Cloudflare Tunnel (QUIC)
        โ”‚  No inbound ports open
        โ–ผ
  cloudflared daemon (client)
        โ”‚
        โ–ผ
  Security Proxy (localhost)
        โ”‚ Blocks: SQLi, SSRF,
        โ”‚  path traversal, scanners
        โ–ผ
  Backend (localhost only)
FLOW 4 โ€” Attack Detection
Network traffic
  โ””โ”€โ–บ Snort IDS (passive tap)
        โ”‚  WAN + VPN + docker
        โ”‚  Custom rules SID 9000001โ€“8
        โ””โ”€โ–บ snort.alert.fast
              โ””โ”€โ–บ Wazuh / OSSEC
                    โ””โ”€โ–บ Correlation
                          โ””โ”€โ–บ Active response

iptables blocklists (daily update):
  โ”œโ”€โ–บ Feodo C2 IPs
  โ”œโ”€โ–บ ET compromised hosts
  โ””โ”€โ–บ Tor exit nodes

fail2ban: auth.log โ†’ >5 fails โ†’ DROP

๐Ÿ—Key Design Decisions

Non-obvious choices and the reasoning behind them.

WireGuard: INSERT not APPEND to FORWARD chain

Docker adds a REJECT rule to the iptables FORWARD chain. Using -A (append) places your WireGuard ACCEPT rule after Docker's REJECT โ€” VPN traffic is silently dropped.

# Wrong โ€” sits after Docker's REJECT
iptables -A FORWARD -i wg0 -j ACCEPT

# Correct โ€” inserted at position 1, before Docker
iptables -I FORWARD 1 -i wg0 -j ACCEPT

IPv6 ULA prefix prevents ISP address leaks

A full tunnel with only AllowedIPs = 0.0.0.0/0 still leaves IPv6 exposed. Assign a ULA prefix (fd00::/8) to the VPN interface and include ::/0 in AllowedIPs.

Multiple tunnels: specific host route wins over subnet route

When two WireGuard tunnels claim overlapping subnets, the secondary tunnel's route blackholes traffic to the VPN server's internal IP.

IFACE=$(route -n get 8.8.8.8 | awk '/interface:/{print $2}')
route add -host VPN_INTERNAL_IP -interface "$IFACE"

TLS: enforce 1.2/1.3, remove legacy from default config

nginx ships a global ssl_protocols directive that includes TLS 1.0/1.1. Remove it at the global level.

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:...";
ssl_prefer_server_ciphers off;

SSH: always maintain a tunnel-based alias

Cloud firewall rules may block port 22 from unknown source IPs. The VPN server's internal IP is only reachable through the tunnel โ€” bypassing external firewall rules entirely.

๐Ÿ”งOperational Fixes

Real issues encountered in production and how they were resolved.

RESOLVED

Full tunnel + unreachable VPN server = total internet loss

AllowedIPs 0.0.0.0/0 routes all traffic into the tunnel. If the VPN server goes down, all traffic disappears. Fix: bring down the tunnel to restore the default gateway.

sudo wg-quick down /path/to/client.conf
RESOLVED

Two active tunnels blackhole traffic to VPN server internal IP

Secondary tunnel claims the VPN subnet. SSH and DNS to the VPN server stop working. Fix: add a specific /32 host route through the primary tunnel interface.

RESOLVED

DNS leaking to public fallback due to routing conflict

Same routing bug causes DNS queries to VPN server to be blackholed. OS falls back to secondary public DNS โ€” queries are unencrypted and outside the tunnel.

RESOLVED

nginx serving TLS 1.0/1.1 โ€” SSLv2 exploit attempt detected

Snort detected an SSLv2 Client_Hello overflow attempt. Removed legacy protocols from global nginx config, enforced TLS 1.2/1.3 only, reloaded zero-downtime.

๐Ÿ”€Technology Alternatives

This architecture is implementation-agnostic. Swap components to suit your environment.

LayerThis StackAlternatives
VPNWireGuardOpenVPN, IPSec/IKEv2, Tailscale, Nebula
Network IDSSnortSuricata, Zeek, Arkime
SIEMWazuhElastic SIEM, Splunk, Graylog
Host IDSOSSECTripwire, AIDE, Falco, Samhain
DNSdnscrypt-proxyPi-hole + DoH, Unbound, AdGuard Home
Firewalliptables + ipsetnftables, pf (BSD/macOS), ufw + ipset
Brute-forcefail2banCrowdSec, DenyHosts, SSHGuard
Reverse proxynginxCaddy, HAProxy, Traefik, Envoy
Tunnel / IngressCloudflare Tunnelngrok, frp, Tailscale Funnel, bore
Threat IntelFeodo + ET + TorAbuseIPDB, Spamhaus, AlienVault OTX

← All articles

Research and direction by Ioannis (John) Konstas; compiled and finalized with AI assistance.

👁· views