openvpn_init.sh 504 B

1234567891011121314151617181920212223
  1. #!/bin/sh
  2. set -e
  3. umask 002
  4. VPN_GW=$(/sbin/ip route | awk '/default/ { print $3 }')
  5. echo Saving gate $VPN_GW
  6. echo DELETING DEFAULT GW
  7. ip route del default
  8. echo SETTING $VPN_IP as the only ip to get routed through $VPN_GW
  9. ip route add $VPN_IP via $VPN_GW
  10. echo Adding 192.168.0.0/16 to the route
  11. ip route add 192.168.0.0/16 via $VPN_GW
  12. echo "nameserver 8.8.8.8" > /etc/resolv.conf
  13. echo Starting openvpn
  14. ip route
  15. cd /vpn
  16. until openvpn vpn; do
  17. echo "Openvpn crashed, respawning"
  18. sleep 10
  19. done