From 8e91a576273baf41434b0bee14309b08333029d7 Mon Sep 17 00:00:00 2001 From: anor Date: Mon, 16 Mar 2026 23:58:39 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=BC=D0=B0=D1=80=D1=88=D1=80?= =?UTF-8?q?=D1=83=D1=82=D1=8B=20=D0=BC=D0=B8=D0=BC=D0=BE=20VPN=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B4=D0=B5=D1=81=D0=BA=D1=82=D0=BE=D0=BF=D0=B0?= =?UTF-8?q?=20(macOS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Автоопределение шлюза (Ethernet → Wi-Fi) - Маршруты для 188.214.107.180, 188.241.196.208, 91.234.54.90 - LaunchDaemon с проверкой каждые 5 сек --- com.custom.staticroutes.plist | 20 ++++++++++++++++++++ set_static_routes.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 com.custom.staticroutes.plist create mode 100644 set_static_routes.sh diff --git a/com.custom.staticroutes.plist b/com.custom.staticroutes.plist new file mode 100644 index 0000000..836fd51 --- /dev/null +++ b/com.custom.staticroutes.plist @@ -0,0 +1,20 @@ + + + + + Label + com.custom.staticroutes + ProgramArguments + + /usr/local/bin/set_static_routes.sh + + RunAtLoad + + StartInterval + 5 + StandardOutPath + /tmp/com.custom.staticroutes.out + StandardErrorPath + /tmp/com.custom.staticroutes.err + + diff --git a/set_static_routes.sh b/set_static_routes.sh new file mode 100644 index 0000000..8a72e2e --- /dev/null +++ b/set_static_routes.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Static routes for desktop +# Ensures VPS IPs always go through local gateway, not VPN tunnel + +LOG="/tmp/com.custom.staticroutes.out" + +# Получаем шлюз физического интерфейса (НЕ default route — может быть VPN utun) +# Перебираем: Ethernet, проводные USB-адаптеры, Wi-Fi +GATEWAY="" +for SVC in "Ethernet" "Wi-Fi"; do + GW=$(/usr/sbin/networksetup -getinfo "$SVC" 2>/dev/null | awk -F': ' '/^Router:/ {print $2}') + if [ -n "$GW" ]; then + GATEWAY="$GW" + break + fi +done + +if [ -z "$GATEWAY" ]; then + exit 0 +fi + +HOSTS="188.214.107.180 188.241.196.208 91.234.54.90" + +for HOST in $HOSTS; do + CURRENT=$(/sbin/route -n get "$HOST" 2>/dev/null | awk '/gateway:/ {print $2}') + if [ "$CURRENT" != "$GATEWAY" ]; then + echo "$(date): $HOST: $CURRENT -> $GATEWAY" >> "$LOG" + /sbin/route -n delete -host "$HOST" >> "$LOG" 2>&1 + /sbin/route -n add -host "$HOST" "$GATEWAY" >> "$LOG" 2>&1 + fi +done