tunnel: авто-DNAT для NDM/81 через wg0 (fix connection refused)

Made-with: Cursor
This commit is contained in:
Андрей Бобырев
2026-04-26 16:02:41 +03:00
parent 858ff8b6ef
commit 4e9f413521
3 changed files with 28 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ WG_IF="${WG_IF:-wg0}"
WG_DIR="/opt/etc/wireguard"
INIT="/opt/etc/init.d/S50kssh-tunnel"
RCD="/opt/etc/rc.d/S50kssh-tunnel"
NAT_TAG="kssh-tunnel:ndm81"
echo "==> kssh-tunnel: удаление клиента ($WG_IF)"
@@ -33,6 +34,11 @@ if command -v iptables >/dev/null 2>&1; then
while iptables -C OUTPUT -o "$WG_IF" -j ACCEPT 2>/dev/null; do
iptables -D OUTPUT -o "$WG_IF" -j ACCEPT 2>/dev/null || break
done
# удалить наши DNAT-правила для доступа к NDM через wg0:81
while iptables -t nat -S PREROUTING 2>/dev/null | grep -q "$NAT_TAG"; do
RULE="$(iptables -t nat -S PREROUTING | grep "$NAT_TAG" | head -n 1 | sed 's/^-A /-D /')"
[ -n "$RULE" ] && iptables -t nat $RULE 2>/dev/null || break
done
fi
# 3. Удалить файлы туннеля (НЕ трогаем чужие WG-конфиги в этой папке)