Skip to content

Instantly share code, notes, and snippets.

@wzyboy
Last active May 11, 2024 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wzyboy/07d80b51ff2f8bc50a7c to your computer and use it in GitHub Desktop.
Save wzyboy/07d80b51ff2f8bc50a7c to your computer and use it in GitHub Desktop.
ocroute
#!/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