Ⅰ 准备工作
- 一部有go host应用专用源授权的手机。
- 安装有openwrt的树莓派(我的型号是3B),理论上其他系统也可以,但是配置文件路径可能会不同。并且,我们需要至少10M的空间。
- 一部能ssh,能浏览网页的设备,如果是手机的话,不需要root。
Ⅱ 配置树莓派
1. 配置网口和ssh
- 由于我们的树莓派处于内网,为了方便起见,将直接关闭其防火墙。如果因为某些原因不能关闭的,请开放相应端口。使用ssh连接树莓派,输入
service firewall stop
service firewall disable
- 新建一个接口,命名为wan,模式设置为dhcp。将网口(不包含无线)划入其中。这样做之后等于说是新增了一台内网服务器。启用wan口的ssh登录,保存。这里如果没有关闭防火墙的话,请开放相应ssh端口和80端口。
- 将wan口的网线插在能正常上网的路由器的任意lan口,记下分配到的ip地址。最好设置成静态ip以方便今后使用。注意,树莓派原lan口的网段不能与路由器重合。
2. 安装软件包
请在luci中搜索并安装以下软件包:
tinyproxy
stunnel
3. 下载相关文件
请将以下文件下载至树莓派的/tmp下备用
私钥文件
hosts文件
注意:两个文件下载好之后,都请去除.zip后缀。
Ⅲ 配置软件
以下操作均需要在ssh中进行
cd /etc/config/ #进入tinyproxy的配置目录
vi tinyproxy.conf
允许所有人使用代理1,注释 Allow 127.0.0.1
#Allow 127.0.0.1
修改监听端口号, 默认 8888
port 8848
cd /etc/stunnel #配置stunnel
vi stunnel.conf
接下来请按照如下配置
; setuid = nobody
; setgid = nogroup
; When running under procd, stay in foreground
foreground = yes
; Don't log to stderr, use syslog
syslog = yes
; 1-7. Use 7 for greatest verbosity
;debug = 5
; Starting here, enter your services or uncomment the examples
; Example:
; If your local httpd does not support HTTPS, use stunnel in remote
; mode to forward TLS connections coming in on port 443 to non-TLS
; on port 80.
; Make sure that the cert is available.
;[httpd]
;accept = 443
;connect = 127.0.0.1:80
;cert = /etc/stunnel/stunnel.pem
client = yes
[http]
accept = 80
#connect = 140.82.48.143:8088
connect = 149.28.247.5:8088
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
[https]
accept = 443
#connect = 140.82.48.143:4433
connect = 149.28.247.5:4433
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
; Example:
; If your local email client does not support TLS,
; use stunnel in client mode to forward non-TLS connections on
; port 143 to TLS-enabled servername:993.
;[imap]
;client = yes
;accept = 143
;connect = servername:993
; Disable peer verification - be sure to understand the limitations of peer
; verification in stunnel when enabling.
;verify = 0
; Default client section:
; stunnel requires at least one section to start successfully.
; You can safely remove this section once you have configured
; your own. We use client mode here as server requires a certificate.
; [dummy]
; client = yes
; accept = localhost:6000
; connect = localhost:6001
特别注意:请注释掉dummy段和一开头的drop privileges段,并且在两个http段之前添加cilent = yes。
然后:wq保存。
tar xzvf /tmp/st.tar.gz
cp /tmp/st.pem /etc/stunnel/stunnel.pem #复制证书文件
chmod 400 stunnel.pem #设置权限400
#接下来替换hosts
cd /etc
mv hosts hosts.bak
cp /tmp/hosts_st hosts
然后检查hosts权限是否和原文件一致。我这里是一致的,无需更改。
Ⅳ 关闭http服务器
由于隧道服务和http服务器冲突,所以我们将禁用http服务,今后将无法通过网页访问openwrt。如果遇到特殊情况可以临时关闭隧道,用ssh开启http服务。
service uhttpd stop
service uhttpd disable
Ⅴ 开始使用
1. 启动代理
service tinyproxy start
service tinyproxy enable #开机启动
2. 启动隧道
service stunnel start
service stunnel enable #开机启动
最后,手机或其他设备连接代理。注意要先在go hosts中更新ip。
然后——享受吧!