39 lines
1.1 KiB
Bash
39 lines
1.1 KiB
Bash
#!/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 "Done!"
|
|
echo "Try this to restart interface : systemctl restart wg-quick@wg_40000"
|
|
echo "And run this to check install : systemctl status networkd-dispatcher"
|
|
|
|
|