下载openvpn static

直接下载static的openvpn,这样就不需要单独再安装so文件了:

http://github.com/downloads/fries/android-external-openvpn/openvpn-static-2.1.1.bz2

新增目录如下:

F:\openvpn>ls -lR
.:
鎬昏 1407
drwx------+ 2 Percy.Peng ????????      0 Mar 31 12:48 openvpn
-rwx------+ 1 Percy.Peng ???????? 907764 Mar 31 10:59 openvpn-static
-rwx------+ 1 Percy.Peng ???????? 529519 Mar 31 10:56 openvpn-static-2.1.1.bz2
-rwx------+ 1 Percy.Peng ????????   1090 Mar 31 11:22 startopenvpn.sh

./openvpn:
鎬昏 12
-rwx------+ 1 Percy.Peng ????????   11 Mar 29 13:52 auth
-rwx------+ 1 Percy.Peng ???????? 1415 Mar 29 13:49 ca.crt
-rwx------+ 1 Percy.Peng ???????? 3470 Mar 31 11:23 client.conf
-rwx------+ 1 Percy.Peng ???????? 3992 Mar 29 13:49 client.crt
-rwx------+ 1 Percy.Peng ????????  887 Mar 29 13:49 client.key

其中./openvpn目录下是存放的相关证书,还有一个auth文件,这个文件是证书的用户名和密码:第一行是用户名,第二行是密码.

startopenvpn.sh是我写的一个脚本文件,用来安装openvpn和启动OpenVPN. 内容如下

#!/bin/sh
#This shell is used to install openvpn on the Android Phone and start the OpenVPN in the SHELL
#You can find more details here:
#http://wiki.impjq.net/doku.php?id=android%E4%B8%8A%E5%AE%89%E8%A3%85openvpn%E6%95%99%E7%A8%8B&do=edit&rev=1269997593
#Date:20100331
#Author:pengjianqing@gamil.com

echo "adb push openvpn-static system/xbin/openvpn"
adb push openvpn-static system/xbin/openvpn

echo "adb shell chmod 775 /system/xbin/openvpn"
adb shell chmod 775 /system/xbin/openvpn

echo "adb shell mkdir /data/openvpn/"
adb shell mkdir /data/openvpn/

echo "adb push  openvpn/client.conf /data/openvpn/"
adb push  openvpn/client.conf /data/openvpn/

echo "adb push  openvpn/ca.crt /data/openvpn/"
adb push  openvpn/ca.crt /data/openvpn/

echo "adb push  openvpn/client.crt /data/openvpn/"
adb push  openvpn/client.crt /data/openvpn/

echo "adb push  openvpn/client.key /data/openvpn/"
adb push  openvpn/client.key /data/openvpn/

echo "adb push  tun.ko /data/openvpn/"
adb push  tun.ko /data/openvpn/

echo "adb shell chmod 777 /data/openvpn/*"
adb shell chmod 777 /data/openvpn/*

echo "adb shell insmod /data/openvpn/tun.ko"
adb shell insmod /data/openvpn/tun.ko

echo "adb shell mkdir  /system/xbin/bb/"
adb shell mkdir /system/xbin/bb/

echo "adb shell busybox  cp /system/bin/ifconfig /system/xbin/bb/"
adb shell busybox  cp /system/bin/ifconfig /system/xbin/bb/
echo "adb shell busybox  cp /system/bin/route /system/xbin/bb/"
adb shell busybox  cp /system/bin/route /system/xbin/bb/

echo "adb shell openvpn --config /data/openvpn/client.conf -auth /data/openvpn/auth"
adb shell openvpn --config /data/openvpn/client.conf -auth /data/openvpn/auth

echo "Also you can run the following commands to start openvpn:"
echo "adb shell"
echo "cd /data/openvpn" 
echo "openvpn --config client.conf -auth auth"

如果要能正常使用这个脚本,需要做如下事情:

  1. 建立如上面所示目录结构
  2. 修改client.conf文件,修改证书目录为绝对路径

ca /data/openvpn/ca.crt
cert /data/openvpn/client.crt
key /data/openvpn/client.ke
做完之后,直接ssh startopenvpn.sh就会安装OpenVPN,并用这个OpenVPN配置文件,启动OpenVPN了.

F:\openvpn>sh startopenvpn.sh
adb push openvpn-static system/xbin/openvpn
1533 KB/s (907764 bytes in 0.578s)
adb shell chmod 775 /system/xbin/openvpn
adb shell mkdir /data/openvpn/
mkdir failed for /data/openvpn/, File exists
adb push  openvpn/client.conf /data/openvpn/
216 KB/s (3470 bytes in 0.015s)
adb push  openvpn/ca.crt /data/openvpn/
44 KB/s (1415 bytes in 0.031s)
adb push  openvpn/client.crt /data/openvpn/
249 KB/s (3992 bytes in 0.015s)
adb push  openvpn/client.key /data/openvpn/
55 KB/s (887 bytes in 0.015s)
adb shell chmod 777 /data/openvpn/*
adb shell cd /data/openvpn &&adb shell openvpn --config /data/openvpn/client.conf -auth /data/openvpn/auth
Wed Mar 31 04:55:14 2010 OpenVPN 2.1.1 i686-pc-linux-gnu [SSL] [LZO2] [EPOLL] built on Feb  2 2010
Wed Mar 31 04:55:14 2010 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Wed Mar 31 04:55:14 2010 WARNING: file '/data/openvpn/client.key' is group or others accessible
Wed Mar 31 04:55:14 2010 LZO compression initialized
Wed Mar 31 04:55:14 2010 Control Channel MTU parms [ L:1544 D:140 EF:40 EB:0 ET:0 EL:0 ]
Wed Mar 31 04:55:14 2010 Data Channel MTU parms [ L:1544 D:1450 EF:44 EB:135 ET:0 EL:0 AF:3/1 ]
Wed Mar 31 04:55:14 2010 Local Options hash (VER=V4): '69109d17'
Wed Mar 31 04:55:14 2010 Expected Remote Options hash (VER=V4): 'c0103fa8'
Wed Mar 31 04:55:14 2010 Attempting to establish TCP connection with 66.96.223.36:1194 [nonblock]
Wed Mar 31 04:55:14 2010 TCP: connect to 66.96.223.36:1194 failed, will try again in 5 seconds: Network is unreachable
Wed Mar 31 04:55:19 2010 TCP: connect to 66.96.223.36:1194 failed, will try again in 5 seconds: Network is unreachable