4.2 KiB
CT200 VPN Gateway — AmneziaWG + vpn-ui
Created: 2026-06-23 Status: ✅ Working
What it is
LXC Container 200 on Proxmox (192.168.170.40). Provides AmneziaWG obfuscated VPN for the whole cluster. Web UI: http://192.168.170.254:8088 (admin / bSNMx7H9OlQ3XiAI)
Access
sshpass -p cityweek ssh root@192.168.170.40 "pct exec 200 -- bash -c 'command'"
# or for complex commands:
sshpass -p cityweek scp file.py root@192.168.170.40:/tmp/
sshpass -p cityweek ssh root@192.168.170.40 "pct push 200 /tmp/file.py /tmp/file.py && pct exec 200 -- python3 /tmp/file.py"
Architecture
Client → Keenetic-170 → CT200 (192.168.170.254) → awg0 → 45.12.135.156:41934 (UfoHosting VPS) → Internet
nftables controls what goes through VPN:
vpn_force_ipsset → traffic to these IPs goes through awg0vpn_exclude_ipsset → traffic to these IPs goes direct (bypass VPN)- dnsmasq resolves domains and dynamically adds IPs to the sets
Services
| Service | Role |
|---|---|
amnezia-vpn.service |
Runs vpn-start.sh → amneziawg-go + awg-quick up |
vpn-ui.service |
Flask app :8088 |
dnsmasq.service |
DNS resolver + nftset population |
vpn-watchdog.timer |
Pings openai.com every 60s, switches servers on 3 failures |
VPN Servers
| Name | Endpoint | Notes |
|---|---|---|
| awgPeak | 45.12.135.156:41934 |
UfoHosting VPS, direct IP (NOT 4min.pw — slower) |
| nuxtcloud | 31.76.18.238:32312 |
reserve, ICMP blocked but tunnel works |
Known Issues and Fixes
1. awg-quick doesn't reliably restart amneziawg-go
Problem: awg-quick down awg0 && awg-quick up awg0 — process exits 0 but amneziawg-go silently fails to start, awg0 disappears.
Fix: Use systemd:
systemctl restart amnezia-vpn.service
sleep 2
ip link show awg0 # verify interface is up
Both reconnect_vpn() in server_manager.py and do_switch_single() in vpn_watchdog.py use this pattern.
2. dnsmasq nftset 4, prefix breaks libnftables 1.0.6
Problem: nftset=/domain/4,inet#vpn_filter#set_name causes silent error:
nftset 4 Error: syntax error, unexpected number, expecting string
IPs not added to nftsets, VPN routing doesn't work.
Fix: Remove 4, prefix. Correct format:
nftset=/domain/inet#vpn_filter#vpn_force_ips
Fixed in:
vpn_manager.pyline ~112:reload_dnsmasq_domains()app.pyline ~136:custom_add()route
3. Cyrillic/IDN domains break dnsmasq
Problem: nftset=/рф/inet#... — dnsmasq can't parse Cyrillic in nftset names. Fails to start.
Fix: Convert to Punycode before writing:
import encodings.idna
dns_val = ".".join(encodings.idna.ToASCII(l).decode() for l in domain.split("."))
# рф → xn--p1ai
Fixed in app.py custom_add() and vpn_manager.py reload_dnsmasq_domains().
4. .bak files in /etc/dnsmasq.d/ crash dnsmasq
Problem: dnsmasq loads ALL files in conf-dir including .conf.bak files.
Fix: Never leave .bak files in /etc/dnsmasq.d/. Delete immediately.
5. Custom domain rules lost on reload
Problem: reload_dnsmasq_domains() overwrites vpn-domains.conf from scratch (services only), erasing custom rules (ru/рф/su/vk.com etc).
Fix: reload_dnsmasq_domains() now also reads custom_rules table from DB and includes domain entries. Applied 2026-06-23.
6. Custom IP rules not restored on CT200 reboot
Problem: Custom IPs from custom_rules table not added to nftsets on startup.
Fix: app.py __main__ startup block now restores custom IP rules from DB and calls reload_dnsmasq_domains(). Applied 2026-06-23.
Files on CT200
| File | Purpose |
|---|---|
/opt/vpn-ui/app.py |
Flask routes, startup init |
/opt/vpn-ui/vpn_manager.py |
nftables, dnsmasq generation |
/opt/vpn-ui/server_manager.py |
reconnect_vpn() via systemctl |
/opt/vpn-ui/vpn_watchdog.py |
watchdog, do_switch_single() |
/opt/vpn-ui/vpn-ui.db |
SQLite: servers, custom_rules, meta |
/etc/dnsmasq.d/vpn-domains.conf |
Auto-generated nftset directives |
/etc/amnezia/configs/awgPeak.conf |
Endpoint = 45.12.135.156:41934 |
/usr/local/bin/vpn-start.sh |
Starts amneziawg-go + awg-quick up |
/etc/nftables-vpn.conf |
nftables rules loaded at startup |