initial commit: wirecon WireGuard stack

Rootless-Docker server (wireguard-go + Caddy sharing netns) and
unprivileged-LXC client (kernel WG + systemd watchdog/monitor/MTU-probe)
with curl-pipeable bootstrap. Tuned for Telekom DSL/LTE Hybrid uplinks.
This commit is contained in:
d4nn13 committed 2026-04-19 18:20:21 +02:00
commit 49b01dfcd3
19 files changed
+770

No files matched your search

@@ -0,0 +1,14 @@
[Unit]
# Make sure we come up after the LAN is ready.
After=network-online.target
Wants=network-online.target
[Service]
# wg-quick@ is Type=oneshot with RemainAfterExit=yes by default.
# If `wg-quick up` itself fails (e.g. transient DNS blip resolving the
# server endpoint at boot), retry a few times before giving up — the
# watchdog takes over from there.
Restart=on-failure
RestartSec=10s
# oneshot needs this for Restart to apply:
# (systemd accepts Restart on oneshot in practice)
@@ -0,0 +1,17 @@
[Unit]
Description=wirecon tunnel continuous monitor
After=wg-quick@wg0.service network-online.target
Wants=wg-quick@wg0.service
[Service]
Type=simple
EnvironmentFile=-/etc/wirecon/wirecon.conf
ExecStart=/usr/local/bin/wirecon-monitor.sh
Restart=always
RestartSec=5s
SyslogIdentifier=wirecon-monitor
# Low priority; observation only.
Nice=5
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,11 @@
[Unit]
Description=wirecon tunnel watchdog (one tick)
After=wg-quick@wg0.service network-online.target
Wants=wg-quick@wg0.service
[Service]
Type=oneshot
EnvironmentFile=-/etc/wirecon/wirecon.conf
ExecStart=/usr/local/bin/wirecon-watchdog.sh
SyslogIdentifier=wirecon-watchdog
Nice=-5
@@ -0,0 +1,14 @@
[Unit]
Description=wirecon watchdog — run check every 20s
After=wg-quick@wg0.service
[Timer]
# Kick off soon after boot, then every 20s.
OnBootSec=30s
OnUnitActiveSec=20s
AccuracySec=1s
# Prevents timer drift if a check takes a while (e.g. during a reconnect).
Unit=wirecon-watchdog.service
[Install]
WantedBy=timers.target
+34
View File
@@ -0,0 +1,34 @@
# /etc/wirecon/wirecon.conf — shared config for wirecon scripts.
# Sourced by bash; keep it simple KEY=VALUE.
# WireGuard interface name
WG_INTERFACE=wg0
# Peer's in-tunnel IP (the server side of the tunnel)
PEER_IP=10.42.0.1
# Reconnect if no handshake has completed within this many seconds.
# WireGuard handshakes every ~120s when traffic flows, so >180s is firmly stale.
HANDSHAKE_MAX_AGE=180
# In-tunnel ping probe
PING_COUNT=3
PING_TIMEOUT=2 # seconds per ping
PING_LOSS_THRESHOLD=3 # total lost-pings across PING_COUNT that trips reconnect
# How many consecutive watchdog ticks must fail before forcing a down/up cycle.
# Guards against single transient LTE hiccups triggering thrash.
FAIL_STREAK_THRESHOLD=2
# MTU probe bounds (for wirecon-mtu-probe.sh)
MTU_MIN=1200
MTU_MAX=1420
# Monitor cadence (seconds between log emissions)
MONITOR_INTERVAL=10
# Log tag (shows up as SYSLOG_IDENTIFIER in journald)
LOG_TAG=wirecon
# Runtime state dir
STATE_DIR=/run/wirecon
+32
View File
@@ -0,0 +1,32 @@
# /etc/wireguard/wg0.conf on the LXC (client) side.
# Rename to wg0.conf and fill in the marked fields.
[Interface]
Address = 10.42.0.2/24
PrivateKey = REPLACE_WITH_CLIENT_PRIVATE_KEY
# Default 1280 for Telekom DSL/LTE Hybrid (GRE overlay eats headroom).
# Run wirecon-mtu-probe.sh to find a better value and update here +
# on the server side.
MTU = 1280
# MASQ traffic from the WG tunnel onto the LAN so hosts on 192.168.1.0/24
# see it as coming from the LXC's LAN IP and reply without needing a
# return route to 10.42.0.0/24.
# Replace eth0 with the LXC's LAN interface name.
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = iptables -t nat -A POSTROUTING -s 10.42.0.0/24 -o eth0 -j MASQUERADE
PostUp = iptables -A FORWARD -i %i -o eth0 -j ACCEPT
PostUp = iptables -A FORWARD -i eth0 -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.42.0.0/24 -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -o eth0 -j ACCEPT
PostDown = iptables -D FORWARD -i eth0 -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
[Peer]
PublicKey = REPLACE_WITH_SERVER_PUBLIC_KEY
Endpoint = REPLACE_WITH_SERVER_PUBLIC_HOST:51820
# Only route the server's tunnel IP through wg0. We do NOT set 0.0.0.0/0
# here because the LXC's default gateway stays on the LAN.
AllowedIPs = 10.42.0.1/32
# Client drives handshakes through the NAT; 25s is standard.
PersistentKeepalive = 25