Last active
May 11, 2024 03:22
-
-
Save wzyboy/07d80b51ff2f8bc50a7c to your computer and use it in GitHub Desktop.
ocroute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash - | |
# Description: A simple script handling default routing for OpenConnect | |
# URL: https://gist.github.com/wzyboy/07d80b51ff2f8bc50a7c | |
# Author: Zhuoyun Wei <wzyboy@wzyboy.org> | |
# Optional: Scripts for chnroutes | |
# https://github.com/jimmyxu/chnroutes | |
VPNUP="/etc/openvpn/vpn-up.sh" | |
VPNDOWN="/etc/openvpn/vpn-down.sh" | |
do_connect() { | |
OLDGW=$(ip route show 0/0 | sed -e 's/^default//') | |
ip link set dev $TUNDEV up | |
ip addr add $INTERNAL_IP4_ADDRESS/32 peer $INTERNAL_IP4_ADDRESS dev $TUNDEV | |
ip route add $VPNGATEWAY $OLDGW | |
ip route add 0/1 dev $TUNDEV | |
ip route add 128/1 dev $TUNDEV | |
[[ -x $VPNUP ]] && $VPNUP || true | |
} | |
do_disconnect() { | |
ip route del $VPNGATEWAY | |
[[ -x $VPNDOWN ]] && $VPNDOWN || true | |
} | |
case $reason in | |
connect) | |
do_connect | |
;; | |
disconnect) | |
do_disconnect | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment