Damus
linux_privacy · 1w
После запуска системы запускаем обновления. Затем отправляем весь трафик через Tor, запустив этот скрипт (оста...
linux_privacy profile picture
Если хотите иметь еще и VPN, например WG, то запустите его по классике и сделайте такой переключатель из тора в вг и обратно в /usr/local/bin (переключение будет через команды sudo toggle-net wg или sudo toggle-net tor):

#!/bin/bash

# Toggle between Tor transparent proxy and WireGuard VPN
# Usage: sudo ./toggle-tor-wireguard.sh [tor|wg|status]

set -e

MODE="${1:-status}"
NFT_CONF_TOR="/etc/nftables.conf"
NFT_CONF_WG="/etc/nftables.wg.conf"
WIREGUARD_CONF="/etc/wireguard/wg0.conf"

show_status() {
echo "=== Current Status ==="
echo ""
echo "--- nftables rules ---"
sudo nft list ruleset 2>/dev/null || echo "No nftables rules loaded"
echo ""
echo "--- Tor service ---"
systemctl is-active tor 2>/dev/null || echo "Tor: inactive"
echo ""
echo "--- WireGuard ---"
wg show 2>/dev/null || echo "WireGuard: no interfaces"
echo ""
echo "--- Default route ---"
ip route | grep default || true
echo ""
echo "--- Checking Tor connectivity ---"
curl -s https://check.torproject.org | grep -i "congratulations\|sorry"
}

disable_tor() {
echo "[*] Disabling Tor transparent proxy..."

# Stop Tor service
if systemctl is-active --quiet tor 2>/dev/null; then
sudo systemctl stop tor
echo " Tor service stopped"
fi

# Flush nftables (remove Tor rules)
sudo nft flush ruleset 2>/dev/null || true
echo " nftables flushed"

# Restore basic nftables or leave empty for WireGuard
sudo nft -f - <<'EOF' 2>/dev/null || true
#!/usr/sbin/nft -f

table ip filter {
chain input {
type filter hook input priority filter; policy accept;
}
chain forward {
type filter hook forward priority filter; policy accept;
}
chain output {
type filter hook output priority filter; policy accept;
}
}
EOF

echo "[*] Tor disabled. Basic firewall restored."
}

enable_wireguard() {
echo "[*] Enabling WireGuard..."

# Check if WireGuard config exists
if [ ! -f "$WIREGUARD_CONF" ]; then
echo "[!] WireGuard config not found: $WIREGUARD_CONF"
echo " Please create your WireGuard configuration first."
exit 1
fi

# Make sure Tor is stopped
disable_tor

# Enable IP forwarding (required for WireGuard)
sudo sysctl -w net.ipv4.ip_forward=1 >/dev/null

# Start WireGuard
sudo wg-quick up wg0 2>/dev/null || true

# Ensure WireGuard starts on boot
sudo systemctl enable wg-quick@wg0 2>/dev/null || true
sudo systemctl start wg-quick@wg0 2>/dev/null || true

echo "[*] WireGuard enabled on wg0"
}

enable_tor() {
echo "[*] Enabling Tor transparent proxy..."

# Stop WireGuard if active
if wg show wg0 >/dev/null 2>&1; then
echo " Stopping WireGuard..."
sudo wg-quick down wg0 2>/dev/null || true
sudo systemctl stop wg-quick@wg0 2>/dev/null || true
sudo systemctl disable wg-quick@wg0 2>/dev/null || true
fi

# Restore Tor nftables rules
if [ -f "$NFT_CONF_TOR" ]; then
sudo nft -f "$NFT_CONF_TOR"
echo " Tor nftables rules restored"
else
echo "[!] Tor nftables config not found: $NFT_CONF_TOR"
exit 1
fi

# Start Tor
sudo systemctl start tor
sudo systemctl enable tor

echo "[*] Tor transparent proxy enabled"
}

case "$MODE" in
tor|t)
enable_tor
;;
wg|wireguard|w)
enable_wireguard
;;
status|s|"")
show_status
;;
*)
echo "Usage: $0 [tor|wg|status]"
echo ""
echo " tor - Enable Tor transparent proxy, disable WireGuard"
echo " wg - Enable WireGuard VPN, disable Tor"
echo " status - Show current network status (default)"
echo ""
exit 1
;;
esac

echo ""
show_status