]> git.sthu.org Git - shutils.git/blob - openvpn/setroute
nextcloud: Rename nextcloud-inotify-sync
[shutils.git] / openvpn / setroute
1 #!/bin/bash
2
3 vpnserver="sthu.org"
4
5 serverip=$(host ${vpnserver} | awk '{ print $4 }')
6 vpnip=$(route -n | grep -m 1 "tun0" | awk '{ print $1 }')
7
8
9 defgw=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $2 }')
10 defif=$(route -n | grep -m 1 "^0.0.0.0" | awk '{ print $8 }')
11 echo "current default gw ${defgw} dev ${defif}"
12 echo ""
13
14
15 echo "add route to ${serverip} via dev ${defif}"
16 route add -host $serverip gw ${defgw} dev ${defif}
17 echo "remove old default route via gw ${defgw}"
18 route del default gw ${defgw}
19 echo "add default gw ${vpnip} (vpnip)"
20 route add default gw ${vpnip}
21
22 echo ""
23 echo "Press to restore default route"
24 read
25
26
27 echo "restore default gw ${defgw} dev ${defif}"
28 route add default gw ${defgw} dev ${defif}
29 echo "remove default route"
30 route del default gw ${vpnip}
31 echo "remove route to ${serverip}"
32 route del ${serverip} gw ${defgw}
33
34