Update the script

This commit is contained in:
2025-10-28 09:50:10 +08:00
parent 86307e309a
commit 08029541ee
3 changed files with 43 additions and 92 deletions

35
keep_set.sh Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
sudo tee /usr/local/bin/setup_route.sh > /dev/null << 'EOF'
#!/bin/bash
TABLE_NAME="ipv4_pub"
TABLE_ID=102
SOURCE_CIDR="44.32.191.0/24"
FROM_PRIORITY=1000
TO_PRIORITY=800
RT_TABLES="/etc/iproute2/rt_tables"
TARGET_IP="10.188.0.44"
GATEWAY=$(ip route get "$TARGET_IP" | grep -oP 'via \K\d+\.\d+\.\d+\.\d+')
ip route del default table "$TABLE_NAME" 2>/dev/null
ip route add default via "$GATEWAY" table "$TABLE_NAME"
ip rule del from "$SOURCE_CIDR" table "$TABLE_NAME" 2>/dev/null
ip rule add from "$SOURCE_CIDR" table "$TABLE_NAME" priority "$FROM_PRIORITY"
ip rule del to "$SOURCE_CIDR" table main 2>/dev/null
ip rule add to "$SOURCE_CIDR" table main priority "$TO_PRIORITY"
echo "44net config done!"
EOF
chmod +x /usr/local/bin/setup_route.sh
sudo tee /etc/networkd-dispatcher/routable.d/00-run-route-script > /dev/null << 'EOF'
#!/bin/bash
/usr/local/bin/setup_route.sh
EOF
sudo chmod +x /etc/networkd-dispatcher/routable.d/00-run-route-script
echo "Install Success,And You can Try sudo systemctl status networkd-dispatcher to see."