-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathip-up
executable file
·28 lines (27 loc) · 860 Bytes
/
ip-up
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/sbin
#clean dns cache
dscacheutil -flushcache
#get gateway
#ovpn
vpngw=`netstat -nr | grep ^0/1 | grep -E 'tun|tap' | head -1 | awk '{print $2}'`
#noneovpn
if [ -z ${vpngw} ]; then
vpngw=`netstat -nr | grep ^default | grep ppp | head -1 | awk '{print $2}'`
fi
#get oldgw
oldgw=`netstat -nr | grep -E '^default|^0/1' | grep -v $(echo ${vpngw}) | head -1 | awk '{print $2}'`
#set the gateway below
#DO NOT uncomment them if nothing goes wrong!!!
#oldgw=192.168.2.1
#vpngw=192.168.0.1
#log
echo $oldgw > /tmp/vpn_oldgw
echo $vpngw > /tmp/vpn_vpngw
source /usr/local/etc/blocked-up.sh
#change default gw
route delete 0/1 $vpngw
route delete 128.0/1 $vpngw
route delete default $vpngw
route delete default $oldgw
route add default $oldgw