This repository has been archived on 2026-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
agent-knowledge-base-archived/dialog-summaries/2026-06-23-vpn-gateway-site2site.md

3 KiB

VPN Gateway Fix + Site-to-Site VPN Setup

Date: 2026-06-23 Topics: CT200 VPN Gateway repair, dnsmasq nftset bugs, site-to-site WireGuard routing

Summary

Two major areas of work:

1. CT200 VPN Gateway (192.168.170.254)

Fixed multiple bugs in the AmneziaWG + vpn-ui stack:

VPN Reconnect reliability:

  • Changed reconnect_vpn() and do_switch_single() to use systemctl restart amnezia-vpn.service
  • Previous approach (awg-quick up/down) silently failed — amneziawg-go didn't start
  • awgPeak endpoint updated to 45.12.135.156:41934 (direct IP, was 4min.pw DNS)

dnsmasq nftset format bug:

  • libnftables 1.0.6 rejects 4,inet#... prefix in nftset directives
  • Silent error: nftset 4 Error: syntax error, unexpected number, expecting string
  • Fixed: removed 4, from all nftset entries in vpn_manager.py, app.py, vpn-domains.conf
  • Verified: .ru domain IPs now correctly appear in vpn_exclude_ips after DNS query

IDN/Punycode domain support:

  • рф (Cyrillic TLD) broke dnsmasq at startup
  • Fixed: convert to Punycode (рф → xn--p1ai) via encodings.idna before writing to dnsmasq
  • Applied in app.py custom_add() and vpn_manager.py reload_dnsmasq_domains()

Persistence across reboots:

  • reload_dnsmasq_domains() now includes custom domain rules from custom_rules DB table
  • app.py startup now restores custom IP rules from DB to nftsets
  • .bak file in /etc/dnsmasq.d/ was crashing dnsmasq — removed

Custom rules configured:

  • .ru, .рф (xn--p1ai), .su → direct access (bypass VPN)
  • vk.com, yandex.com → direct access

2. Site-to-Site VPN: 192.168.170.x ↔ 192.168.255.x

Problem: Bidirectional access between home LAN and WiFi network not working.

Root causes found:

  1. Keenetic-170 Wireguard2 had security-level public → stateful firewall blocked public→private forwarding
  2. WiFi router isolate-private + Keenetic firewall blocked forwarding from Bridge0 clients to Wireguard1

Fixes applied:

  • Keenetic Peak (192.168.170.1): interface Wireguard2 → security-level private
  • WiFi router (192.168.255.1): ip nat Wireguard1 + keep security-level public on Wireguard1
    • NAT masquerades client traffic as 172.16.16.2 (router's tunnel IP)
  • Both configs saved (system configuration save)

Result: All cluster nodes reachable from WiFi:

  • 192.168.170.1 (router): ✅ ~44ms
  • 192.168.170.22 (TrueNAS): ✅ ~75ms
  • 192.168.170.30 (Docker): ✅ ~258ms
  • 192.168.170.40 (Proxmox): ✅ ~301ms
  • 192.168.170.70 (qore AI): ✅ ~35ms

Internet routing unchanged: home→ISP, WiFi→VPN(UfoHosting).

Key Learnings

  • Keenetic WireGuard site-to-site: responder side needs security-level private to allow tunnel→LAN forwarding
  • WiFi router with isolate-private: keep WG tunnel as public + ip nat for client access
  • dnsmasq nftset: always test dnsmasq --test before reloading, check for Cyrillic in domain names
  • awg-quick is unreliable for restarts — always use systemd service