在路由器上使用OpenWrt
不知道从什么时候起, 家里就有一堆路由器了。前段时间觉得每个用起来都不太对劲,所以就全刷openwrt了。 发现还挺好用的, 又可以折腾了。
freedom-routes
首先折腾的是用openwrt拨VPN,然后手动设置国内的路由表。写了一个脚本如下:
#!/bin/sh
case "$1" in
update)
cd /tmp
rm routes-up.sh routes-down.sh
wget http://dl.saber.li/freedom-routes/linux/routes-up.sh
wget http://dl.saber.li/freedom-routes/linux/routes-down.sh
sed -e 's/gateway=.*/gateway=192.168.1.1/' routes-up.sh >routes-up.new
mv -f routes-up.new routes-up.sh
;;
start)
source /tmp/routes-up.sh
;;
stop)
source /tmp/routes-down.sh
;;
*)
echo "usage: $0 start|stop|update"
;;
esac
ssh隧道
前面介绍的用VPN+路由表的方案并不是所有的地方都能用,有些地方连vpn都拨不了。为了应急,先用ssh建立一个sock5的代理服务器。
首先要安装个完整点的ssh客户端:
$ opkg update
$ opkg install openssh-client
文件:/etc/init.d/ssh-proxy
:
#!/bin/sh /etc/rc.common
START=90
APP=ssh-proxy
PID_FILE=/var/run/$APP.pid
start() {
start-stop-daemon -S -x ssh -p $PID_FILE -m -b -- -N -D0.0.0.0:1080 root@myserver.com -o ServerAliveInterval=60
}
stop() {
start-stop-daemon -K -n ssh -p $PID_FILE -s TERM
rm -rf $PID_FILE
}
以上脚本能够在启动时自动使用ssh建立隧道, 前提是用key来认证。
SwitchyOmega
有了sock5代理服务器以后,使用chrome的插件SwitchyOmega就可以使用代理了。 使用AutoProxy模式, 规则列表为的地址为: https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
dnscrypt
前面的方案虽说已经能满足大部分的需要了, 但是还不够完美。 使用VPN的IP解析出来的地址, 都是离VPN比较近的。 所以还是要彻底解决DNS污染的问题。
$ cd /tmp
$ wget http://exopenwrt.and.in.net/barrier_breaker/ar71xx/packages/exOpenWrt/dnscrypt-proxy_1.4.0-5.E_ar71xx.ipk
$ wget http://exopenwrt.and.in.net/barrier_breaker/ar71xx/packages/exOpenWrt/libsodium_0.7.0-1.E_ar71xx.ipk
$ opkg install libsodium_0.7.0-1.E_ar71xx.ipk
$ opkg install dnscrypt-proxy_1.4.0-5.E_ar71xx.ipk
配置文件:/etc/config/dnscrypt-proxy
config dnscrypt-proxy
option address '127.0.0.1'
option port '2053'
option resolver 'opendns'
最后在DHCP配置中把DNS forwardings改为dnscrypt的地址:127.0.0.1#2053
redsocks2
安装:
$ cd /tmp
$ wget http://downloads.sourceforge.net/project/openwrt-dist/redsocks2/0.60-769a5b0/redsocks2_0.60-2_ar71xx.ipk
$ opkg install redsocks2_0.60-2_ar71xx.ipk
ShadowSocks
客户端安装:
$ cd /tmp
$ wget http://downloads.sourceforge.net/project/openwrt-dist/shadowsocks-libev/2.1.4-87ec497/ar71xx/shadowsocks-libev-spec-polarssl_2.1.4-1_ar71xx.ipk
$ wget http://downloads.sourceforge.net/project/openwrt-dist/luci-app/shadowsocks-spec/luci-app-shadowsocks-spec_1.3.0-1_all.ipk
$ opkg install shadowsocks-libev-spec-polarssl_2.1.4-1_ar71xx.ipk
$ opkg install luci-app-shadowsocks-spec_1.3.0-1_all.ipk
服务端:
$ sudo add-apt-repository "deb http://shadowsocks.org/debian wheezy main"
$ sudo apt-get update
$ sudo apt-get install shadowsocks
网络模拟
首先安装:
$ opkg update
$ opkg install kmod-netem tc
延时模拟:
$ tc qdisc add dev eth0 root netem delay 1000ms
获取路由器的超级密码:
- 进入http://192.168.1.1/manager_dev_config_t.gch, 下载配置文件
- offzip.exe -a config.bin . 0
- 查找admin
将sock5代理转为HTTP代理
$ opkg install privoxy