Files
Server-scripts/network/routing.sh
T

50 lines
2.0 KiB
Bash
Raw Normal View History

2026-04-14 23:55:37 +02:00
#! /bin/bash
# Niftiest Software – www.niftiestsoftware.com
# Modified version by HTPC Guides – www.htpcguides.com
echo VPNUSER: $VPNUSER
if [[ "$(grep $VPNUSER /etc/iproute2/rt_tables)" == "" ]]; then
sudo sh -c 'echo "1 deluge-user" >> /etc/iproute2/rt_tables'
fi
if [ "$1" == "reverse" ]; then
VPNUSER="$2"
printf "reverse table for ${VPNUSER}\n"
ip route flush table ${VPNUSER}
ip route replace default via 127.0.0.1 table ${VPNUSER}
ip route flush cache
exit 0
fi
#${VPNIF}="tun+"
#VPNUSER="deluge-user"
#VPNIP="10.15.0.*"
printf "${LOCALIP}\n${NETIF}\n${VPNIP}\n${VPNIF}\n${P2PIP}\n${VPNUSER}\n"
printf "Flush old ${VPNUSER} table\n"
ip route flush table ${VPNUSER}
#printf "Flush Main Table(Revert VPN Changes) and restore default\n"
#ip route flush table main
#ip route add 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.2 metric 100
#ip route add 37.48.66.67 via 10.0.0.138 dev eth0 proto static metric 100
#ip route add 169.254.0.0/16 dev eth0 proto static scope link metric 1000
#ip route add default via 10.0.0.138 dev eth0 proto static metric 100
printf "Add rule for marked packets\n"
if [[ $(ip rule list | grep -c ${MARK_ID}) == 0 ]]; then
ip rule add from all fwmark ${MARK_ID} lookup ${VPNUSER}
fi
printf "Replace Default, Append Default, Flush cache\n"
ip route replace default via ${P2PIP} table ${VPNUSER}
#ip route append default via 127.0.0.1 dev lo table ${VPNUSER}
for PUB_IP_ADDR in ${PUBIP[@]}; do
echo "ip route add ${PUB_IP_ADDR}/32 via ${P2PIP} dev ${VPNIF} table ${VPNUSER}"
ip route add ${PUB_IP_ADDR}/32 via ${P2PIP} dev ${VPNIF} table ${VPNUSER}
done
#ip route add 0.0.0.0/1 via ${VPNIP} dev ${VPNIF} table ${VPNUSER}
#ip route add 128.0.0.0/1 via 10.15.0.125 table ${VPNUSER}
#ip route add 10.15.0.1/32 via ${VPNIP} dev ${VPNIF} table ${VPNUSER}
#ip route add ${P2PIP} dev ${VPNIF} proto kernel scope link src ${VPNIP} table ${VPNUSER}
ip route flush cache
printf "run update-resolv-conf script to set VPN DNS\n"
/etc/openvpn/update-resolv-conf
exit 0