-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtap-local.sh
54 lines (42 loc) · 1.06 KB
/
tap-local.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
PHY_DEV="ens33"
TAP_DEV="tap0"
TAP_MTU="1400"
SERVER_IP="127.0.0.1"
SERVER_PORT="2020"
SERVER_KEY="12345678"
## green to echo
function green(){
echo -e "\033[32m$1 \033[0m"
}
## Error
function bred(){
echo -e "\033[31m\033[01m$1 \033[0m"
}
## warning
function byellow(){
echo -e "\033[33m\033[01m$1 \033[0m"
}
killall -9 simplevpn
./simplevpn -m client -s $SERVER_IP -p $SERVER_PORT -k $SERVER_KEY &
sleep 1
ifconfig $TAP_DEV mtu $TAP_MTU
# killall -9 udhcpc
PID_UDHCPC=`ps -ef | grep udhcpc | grep ${TAP_DEV} | awk '{print $2}'`
if [ -n "$PID_UDHCPC" ]; then
echo "pid of udhcpc: "${PID_UDHCPC}
kill -9 $PID_UDHCPC
fi
udhcpc -i $TAP_DEV
# route add default gw 10.10.0.1
PHY_GW=`ip route | grep via | grep default | grep ${PHY_DEV} | awk '{print $3}'`
if [ -n "$PHY_GW" ]; then
ip route del default gw $PHY_GW
ip route add $SERVER_IP via $PHY_GW
echo "delete your default gateway: "${PHY_GW}
fi
if [ -z "$PHY_GW" ]; then
byellow "[warn] not found default gateway of "${PHY_DEV}
fi
echo "your remote server: "${SERVER_IP}":"${SERVER_PORT}
green "$0 done"