From d8cf81cacda2850ac4423926888167a465579c60 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 29 Oct 2012 18:08:58 +0100 Subject: [PATCH] add openvpn scripts --- openvpn/setroute | 34 ++++++++++++++++++++++++++++++++++ openvpn/start | 2 ++ 2 files changed, 36 insertions(+) create mode 100755 openvpn/setroute create mode 100755 openvpn/start diff --git a/openvpn/setroute b/openvpn/setroute new file mode 100755 index 0000000..26081b8 --- /dev/null +++ b/openvpn/setroute @@ -0,0 +1,34 @@ +#!/bin/bash + +vpnserver="sthu.org" + +serverip=$(host ${vpnserver} | awk '{ print $4 }') +vpnip=$(route -n | grep -m 1 "tun0" | awk '{ print $1 }') + + +defgw=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $2 }') +defif=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $8 }') +echo "current default gw ${defgw} dev ${defif}" +echo "" + + +echo "add route to ${serverip} via dev ${defif}" +route add -host $serverip gw ${defgw} dev ${defif} +echo "remove old default route via gw ${defgw}" +route del default gw ${defgw} +echo "add default gw ${vpnip} (vpnip)" +route add default gw ${vpnip} + +echo "" +echo "Press to restore default route" +read + + +echo "restore default gw ${defgw} dev ${defif}" +route add default gw ${defgw} dev ${defif} +echo "remove default route" +route del default gw ${vpnip} +echo "remove route to ${serverip}" +route del ${serverip} gw ${defgw} + + diff --git a/openvpn/start b/openvpn/start new file mode 100755 index 0000000..9f2975b --- /dev/null +++ b/openvpn/start @@ -0,0 +1,2 @@ +#!/bin/sh +openvpn --config /etc/openvpn/sthu.org/tun0.conf verb 6 -- 2.39.5