WireGuard Mesh VPN, Cryptokey Routing & Linux nftables / ufw Firewall Hardening Guide
Lock down servers behind minimalist kernel cryptography: deploy WireGuard UDP tunnels with AllowedIPs cryptokey routing, avoid common split-tunnel leaks, and harden Linux hosts with modern nftables and ufw egress/ingress rules.
1. WireGuard Minimalism & AllowedIPs Cryptokey Routing
AllowedIPs.umask 077
wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.66.0.1/24
ListenPort = 51820
PrivateKey = <SERVER_PRIVATE_KEY>
[Peer]
PublicKey = <LAPTOP_PUBLIC_KEY>
AllowedIPs = 10.66.0.2/32AllowedIPs acts simultaneously as both a route-table selector and strict source-IP access control list.
| AllowedIPs Setting | Traffic Routing Behavior | Ideal Use Case | Copy |
|---|---|---|---|
| 10.66.0.0/24 | Routes only private admin VPN subnet | Split tunnel for SSH, Postgres, Grafana | |
| 0.0.0.0/0, ::/0 | Tunnels 100% IPv4 + IPv6 internet traffic | Untrusted cafe/airport public Wi-Fi protection | |
| 10.66.0.2/32 | Assigns single-host route to peer | Server-side peer definition |
2. Migrating From iptables Legacy Rules to Atomic nftables
nftables, replacing fragmented iptables/ip6tables chains with unified inet IPv4+IPv6 tables, O(1) inline hash sets for blocklists, and atomic rule swaps.flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iif "lo" accept
ct state established,related accept
ip protocol icmp accept
ip6 nexthdr ipv6-icmp accept
udp dport 51820 accept
tcp dport { 80, 443 } accept
iifname "wg0" tcp dport 22 accept
}
chain forward { type filter hook forward priority 0; policy drop; }
chain output { type filter hook output priority 0; policy accept; }
}Restricts SSH (port 22) strictly to authenticated wg0 VPN interfaces while exposing only HTTPS and UDP WireGuard externally.
3. The Classic Docker + ufw Firewall Bypass Trap
ufw deny! Why? Docker injects rules directly into the netfilter DOCKER-USER / PREROUTING NAT chain, which kernel packets traverse before reaching ufw host INPUT rules. Always bind container ports to loopback or private WireGuard IPs (`-p 127.0.0.1:5432:5432`).# SAFE: Binds exclusively to localhost instead of 0.0.0.0
ports:
- "127.0.0.1:5432:5432"
# Verify listening sockets externally with ss:
ss -tulnpNever rely solely on ufw to block a container published on 0.0.0.0.
4. NAT Traversal, PersistentKeepalive & WireGuard MTU (1420 vs 1280)
MTU = 1420 (or `1280` on strict IPv6/cellular paths) and configure PersistentKeepalive = 25 on clients behind NAT so stateful firewall mappings never time out.Related Free Online Tools
Put these techniques into practice immediately with our privacy-first browser utilities:
Compute exact AllowedIPs CIDR subnets, network bounds, and host counts for WireGuard interfaces.
Convert firewall IP ranges into minimal CIDR blocks for nftables sets and Allowlists.
Format interface MAC addresses and synthesize valid LAA virtual NIC addresses for VMs.
Independent software developer focused on client-side architectures, local-first computing, WebAssembly, and privacy-first web systems.