#!/usr/bin/env bash set -e echo "=======================================" echo " VPN NODE NETWORK OPTIMIZER" echo "=======================================" if [[ $EUID -ne 0 ]]; then echo "❌ Run as root" exit 1 fi echo echo "🔍 Detecting default interface..." DEFAULT_IFACE=$(ip route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="dev"){print $(i+1); exit}}') if [[ -z "$DEFAULT_IFACE" ]]; then echo "❌ Could not auto-detect interface" echo "Available interfaces:" ip -o link show | awk -F': ' '{print $2}' | grep -v lo read -rp "âžĄī¸ Enter interface manually: " IFACE else echo "âžĄī¸ Detected interface: $DEFAULT_IFACE" read -rp "Press Enter to use [$DEFAULT_IFACE] or type another: " IFACE IFACE=${IFACE:-$DEFAULT_IFACE} fi echo echo "✅ Using interface: $IFACE" # ==== SAFE CHECK (NO set -e BREAK) ==== set +e ip link show "$IFACE" >/dev/null 2>&1 RC=$? set -e if [[ $RC -ne 0 ]]; then echo "❌ Interface '$IFACE' does not exist" exit 1 fi echo echo "âš™ī¸ Applying sysctl network tuning..." cat >/etc/sysctl.d/99-vpn-lowlatency.conf </dev/null echo "✅ sysctl applied" echo echo "âš™ī¸ Applying fq_codel on $IFACE" tc qdisc del dev "$IFACE" root 2>/dev/null || true tc qdisc add dev "$IFACE" root fq_codel target 5ms interval 100ms quantum 1514 ecn echo "✅ fq_codel active" echo echo "âš™ī¸ Disabling NIC offloads" ethtool -K "$IFACE" gro off gso off tso off 2>/dev/null || true echo echo "🎉 DONE — Network optimized" echo "â„šī¸ Reboot recommended (not mandatory)"