基于OPENWRT 配置自动穿墙路由器

本文编写于3456天前,最后编辑于 2527天前,部分内容可能已经过时,请您自行斟酌确认。

手上有联想云路由一个,在网上查了一些例子,使用shadowsocks自动穿墙很好用.以下是配置步骤

opkg update
opkg install libopenssl pdnsd iptables-mod-nat-extra
wget http://dl.bintray.com/aa65535/opkg/shadowsocks-libev/2.5.6/ramips/shadowsocks-libev-polarssl_2.5.6-1_ramips_24kec.ipk
opkg install shadowsocks-libev_1.4.8-3_ramips_24kec.ipk
opkg install https://github.com/shadowsocks/luci-app-shadowsocks/releases/download/v1.3.7/luci-app-shadowsocks_1.3.7-1_all.ipk

不同的路由要下载不同架构的版本.下错了是安装不上的,联想云路由是 MT7620A芯片,应该下载ramips架构,详细可参考如下架构列表:

架构            CPU型号
ar71xx            AR7xxx/AR9xxx/QCA9xxx
atheros            AR231x/AR5xxx
bcm53xx            BCM47xx/53xx (ARM CPU)
brcm47xx            BCM47xx/53xx (MIPS)
brcm63xx            BCM63xx
ramips_24kec    RT3x5x/RT5350/MT7620a/MT7620n/MT7621

若 ramips_24kec 包安装时出现 incompatible with the architectures configured 错误,
可编辑 /etc/opkg.conf 调整架构支持, 在文件末尾添加(也可以通过 LuCI 设置页面修改):

dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
arch all 100
arch ralink 200
arch ramips 300
arch ramips_24kec 400
src/gz 15.05.1_base http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/packages/base/
src/gz 15.05.1_management http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/packages/management
src/gz 15.05.1_packages http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/packages/packages
src/gz 15.05.1_routing http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/packages/routing
src/gz 15.05.1_telephony http://downloads.openwrt.org/chaos_calmer/15.05.1/ramips/mt7620/packages/telephony

添加完成后使用 opkg update 命令更新一次
再次使用 opkg install {packagename}.ipk 命令安装
编辑shadowsocks的配置信息/etc/shadowsocks.json
格式如下:

{
    "server":"[服务器IP地址]",
    "server_port":[服务器端口],
    "local_port":[本地端口,稍后iptables会用到],
    "password":"[密码]",
    "timeout":600,
    "method":"[加密方式]"
}

修改启动脚本

vi /etc/init.d/shadowsocks

修改为如下

#!/bin/sh /etc/rc.common

START=95

SERVICE_USE_PID=1
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1

CONFIG=/etc/shadowsocks.json

start() {
        # Client Mode
        service_start /usr/bin/ss-local -c $CONFIG

        # Proxy Mode
        #service_start /usr/bin/ss-redir -c $CONFIG
}

stop() {
        # Client Mode
        service_stop /usr/bin/ss-local

        # Proxy Mode
        #service_stop /usr/bin/ss-redir
}

配置pdnsd解决DNS污染
通过pdnsd使用TCP协议向国外的上级DNS查询而避过DNS污染,然后在本地提供一个1053端口的DNS供dnsmasq使用。
修改pdnsd的配置文件 /etc/pdnsd.conf:
注意关注中文注释部分,如果复制记得把中文注释删掉。。。其他部分如果您需要,再自行修改:

# 这一段全局配置需要修改:

global {
    # debug = on;          
    perm_cache=1024;
    cache_dir="/var/pdnsd";
    run_as="nobody";
    server_port = 1053;    # !!!使用 1053 作为 dns 端口, 默认是 53,一定要修改否则会跟默认dnsmasq冲突
    server_ip = 127.0.0.1;  #我们只需要处理本机转发的DNS查询,所以不需要更改
    status_ctl = on;
    query_method=tcp_only; # !!!最重要的配置, 只使用 tcp 查询上级 dns
    min_ttl=15m;
    max_ttl=1w;
    timeout=10;
}

#……

# 自行增加下面这一段,pdnsd默认是没有提供上游DNS服务器的(默认配置文件中用各种注释方式把自带的注释掉了):

server {
    label= "googledns";           # 这个label随便写
    ip = 8.8.8.8; # 这里为上级 dns 的 ip 地址,要求必须支持TCP查询,相关说明见后文注解
    root_server = on;        # 设置为 on。
    uptest = none;           # 不去检测 dns 是否无效.
}
        # …… 后面不需要修改的就不贴出来了。

启用pdnsd,并设置为开机启动:

/etc/init.d/pdnsd enable
/etc/init.d/pdnsd start

使用iptables屏蔽掉功夫网DNS污染返回的虚假IP(这个方法已失效)

iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4A7D7F66|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4A7D9B66|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4A7D2766|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4A7D2771|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|BDA31105|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D155E58A|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|F9812E30|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|80797E8B|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|9F6A794B|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|A9840D67|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|C043C606|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|CA6A0102|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|CAB50755|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|CBA1E6AB|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|CB620741|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|CF0C5862|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D0381F2B|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D1913632|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D1DC1EAE|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D1244921|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D35E4293|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D5A9FB23|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D8DDBCB6|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|D8EAB30D|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|F3B9BB27|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|253D369E|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|042442B2|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|2E52AE44|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|3B1803AD|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|402158A1|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4021632F|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4042A3FB|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4168CAFC|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|41A0DB71|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|422DFCED|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|480ECD68|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|480ECD63|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4E10310F|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|0807C62D|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|5D2E0859|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|FD9D0EA5|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|364C8701|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|1759053C|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|31027B38|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|4D04075C|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|C504040C|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|76053106|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|BC050460|" --from 60 --to 180  -j DROP
iptables -t mangle -I PREROUTING -p udp --sport 53 -m string --algo bm --hex-string "|BDA31105|" --from 60 --to 180  -j DROP

iptables -t mangle -I PREROUTING -p udp --sport 53 -m u32 --u32 "0&0x0F000000=0x05000000 && 0>>22&0x3C@8&0x810F=0x8000 && 0>>22&0x3C@12&0xFFFF=0x0000" -j DROP

设置dnsmasq对特定域名使用本地的pdnsd进行解析:
为了保持配置文件整洁,建议在 /etc/dnsmasq.conf 最后加入:

echo "conf-dir=/etc/dnsmasq.d" >>/etc/dnsmasq.conf

然后新建目录 /etc/dnsmasq.d ,在里面加入一个conf,名字任选。譬如 /etc/dnsmasq.d/fuckgfw.conf ,下面是我的文件内容,你可以按自己需要整理自己的:

#Google and Youtube
server=/.google.com/127.0.0.1#1053
server=/.google.com.hk/127.0.0.1#1053
server=/.gstatic.com/127.0.0.1#1053
server=/.ggpht.com/127.0.0.1#1053
server=/.googleusercontent.com/127.0.0.1#1053
server=/.appspot.com/127.0.0.1#1053
server=/.googlecode.com/127.0.0.1#1053
server=/.googleapis.com/127.0.0.1#1053
server=/.gmail.com/127.0.0.1#1053
server=/.google-analytics.com/127.0.0.1#1053
server=/.youtube.com/127.0.0.1#1053
server=/.googlevideo.com/127.0.0.1#1053
server=/.youtube-nocookie.com/127.0.0.1#1053
server=/.ytimg.com/127.0.0.1#1053
server=/.blogspot.com/127.0.0.1#1053
server=/.blogger.com/127.0.0.1#1053

#FaceBook
server=/.facebook.com/127.0.0.1#1053
server=/.thefacebook.com/127.0.0.1#1053
server=/.facebook.net/127.0.0.1#1053
server=/.fbcdn.net/127.0.0.1#1053
server=/.akamaihd.net/127.0.0.1#1053

#Twitter
server=/.twitter.com/127.0.0.1#1053
server=/.t.co/127.0.0.1#1053
server=/.bitly.com/127.0.0.1#1053
server=/.twimg.com/127.0.0.1#1053
server=/.tinypic.com/127.0.0.1#1053
server=/.yfrog.com/127.0.0.1#1053

经过上面的设置之后,如果使用路由器作为DNS服务器,就可以避免被DNS污染了;但是如果局域网内的主机手动设置了DNS服务器,还是难免遭到DNS污染。

为了避免这个问题,我们可以强制局域网内的主机都使用路由器的DNS,通过设置防火墙规则,将所有DNS解析的请求"劫持"到路由器上,从未避免局域网内的主机使用自定义DNS时被污染,在/etc/firewall.user上增加两条规则即可:

iptables -t nat -A PREROUTING -s 路由器IP/24 -p udp --dport 53 -j DNAT --to 路由器IP
iptables -t nat -A PREROUTING -s 路由器IP/24 -p tcp --dport 53 -j DNAT --to 路由器IP

使用iptables对流量进行重定向
直接复制下面的脚本,跟我一样保存为/usr/bin/ss-black.sh,注意运行前要给它运行权限:

chmod +x /usr/bin/ss-black.sh

以下为脚本内容:

#!/bin/sh

#create a new chain named SHADOWSOCKS
iptables -t nat -N SHADOWSOCKS

#Redirect what you want

#Google
iptables -t nat -A SHADOWSOCKS -p tcp -d 74.125.0.0/16 -j REDIRECT --to-ports 1080
iptables -t nat -A SHADOWSOCKS -p tcp -d 173.194.0.0/16 -j REDIRECT --to-ports 1080

#Youtube
iptables -t nat -A SHADOWSOCKS -p tcp -d 208.117.224.0/19 -j REDIRECT --to-ports 1080
iptables -t nat -A SHADOWSOCKS -p tcp -d 209.85.128.0/17 -j REDIRECT --to-ports 1080

#Twitter
iptables -t nat -A SHADOWSOCKS -p tcp -d 199.59.148.0/22 -j REDIRECT --to-ports 1080
iptables -t nat -A SHADOWSOCKS -p tcp -m iprange --dst-range 117.18.232.0-117.18.239.255 -j REDIRECT --to-ports 1080

#Shadowsocks.org
iptables -t nat -A SHADOWSOCKS -p tcp -d 199.27.76.133/32 -j REDIRECT --to-ports 1080

#1024
iptables -t nat -A SHADOWSOCKS -p tcp -d 184.154.128.246/32 -j REDIRECT --to-ports 1080

#Facebook
iptables -t nat -A SHADOWSOCKS -p tcp -d 173.252.64.0/18 -j REDIRECT --to-ports 1080

#Dropbox
iptables -t nat -A SHADOWSOCKS -p tcp -d 108.160.160.0/20 -j REDIRECT --to-ports 1080

#SourceForge
iptables -t nat -A SHADOWSOCKS -p tcp -d 216.34.181.0/24 -j REDIRECT --to-ports 1080

#Anything else should be ignore
iptables -t nat -A SHADOWSOCKS -p tcp -j RETURN

# Apply the rules
iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS

如果需要添加你自己需要访问的域名很简单。首先使用dig或者nslookup获取域名对应的正确IP,然后借助APNIC的IP WHOIS工具:(http://wq.apnic.net/apnic-bin/whois.pl) 可以轻松的获得大部分IP段。以facebook为例:

dig获取的正确IP为:173.252.110.27。
通过APNIC查询到173.252.64.0/18均属于facebook。则添加

iptables -t nat -A SHADOWSOCKS -p tcp -d 173.252.64.0/18 -j REDIRECT --to-ports 1080

设置路由:

/usr/bin/ss-black.sh 
/etc/init.d/shadowsocks enable
/etc/init.d/shadowsocks start

其他问题

查看iptables的NAT表来检查路由表是否已经成功加载:

iptables -t nat --list

通过lsof监测端口 查看这些程序跑起来没有

[root@PandoraBox:/root]# lsof -i:1080
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
ss-local 2619 root    3u  inet   2989      0t0  TCP *:socks (LISTEN)
ss-local 2619 root    7u  inet   3140      0t0  TCP PandoraBox.lan:socks->192.168.1.2:52230 (ESTABLISHED)
ss-local 2619 root    8u  inet   3167      0t0  TCP PandoraBox.lan:socks->192.168.1.2:52236 (ESTABLISHED)
ss-local 2619 root   10u  inet   3141      0t0  TCP PandoraBox.lan:socks->192.168.1.2:52231 (ESTABLISHED)
ss-local 2619 root   11u  inet   3142      0t0  TCP PandoraBox.lan:socks->192.168.1.5:44904 (ESTABLISHED)
ss-local 2619 root   12u  inet   3169      0t0  TCP PandoraBox.lan:socks->192.168.1.2:52240 (ESTABLISHED)
[root@PandoraBox:/root]# lsof -i:1053
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
pdnsd   2593 nobody    4u  inet   2907      0t0  TCP localhost:1053 (LISTEN)
pdnsd   2593 nobody    5u  inet   2908      0t0  UDP localhost:1053
[root@PandoraBox:/root]# lsof -i:53
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dnsmasq 2560 nobody    6u  inet   2849      0t0  UDP *:domain
dnsmasq 2560 nobody    7u  inet   2850      0t0  TCP *:domain (LISTEN)

停止服务器:

killall ss-redir  # 关闭shadowsocks。
/etc/init.d/firewall restart # 清除流量重定向配置。

OpenWrt路由器自动更新国内重要网站名单

登陆路由器后:

root@OpenWrt:~# cd /usr/bin
root@OpenWrt:~# touch updatednsmasq
root@OpenWrt:~# chmod +x updatednsmasq
root@OpenWrt:~# vi updatednsmasq

增加如下内容:

#!/bin/sh                                                                                                                                                               
cnlist() {                                                                                                                                                              
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/accelerated-domains.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/bogus-nxdomain.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf
}         
cnlist

国内广告屏蔽

dnsmasq支持基于域名的广告屏蔽方式,这种屏蔽方式比较粗糙,屏蔽效果会比浏览器广告屏蔽插件差很多,并且可能导致有些网站不能顺利打开。

在updatednsmasq文件中加入:

adblock() {                                                                                                                                                             
    wget -4 --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt |                                                     
    grep ^\|\|[^\*]*\^$ |                                                                                                                                           
    sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' | uniq > /etc/dnsmasq.d/adblock.conf                                                                        

    wget -4 --no-check-certificate -O - https://raw.githubusercontent.com/kcschan/AdditionalAdblock/master/list.txt |                                               
    grep ^\|\|[^\*]*\^$ |                                                                                                                                           
    sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' >> /etc/dnsmasq.d/adblock.conf                                                                              
} 

最后完整的updatednsmasq就是这样:

#!/bin/sh
cnlist() {
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/accelerated-domains.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/bogus-nxdomain.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/google.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf
    wget -4 --no-check-certificate -O /etc/dnsmasq.d/apple.china.conf https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf
    }
adblock() {
    wget -4 --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt |
    grep ^\|\|[^\*]*\^$ |
    sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' | uniq > /etc/dnsmasq.d/adblock.conf

    wget -4 --no-check-certificate -O - https://raw.githubusercontent.com/kcschan/AdditionalAdblock/master/list.txt |
    grep ^\|\|[^\*]*\^$ |
    sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' >> /etc/dnsmasq.d/adblock.conf
}
chnroute() {
    wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /etc/chinadns_chnroute.txt
}
cnlist
adblock
chnroute

/etc/init.d/dnsmasq restart

计划任务:定时更新dnsmasq配置文件和自动重启 ss-redir
加执行权限

chmod +x /usr/bin/updatednsmasq

root@OpenWrt:~# crontab -e
输入以下内容:

*/30 * * * * isfound=$(ps | grep "ss-redir" | grep -v "grep"); if [ -z "$isfound" ]; then echo "$(date): restart ss-redir...">>/tmp/log/ss-monitor.log && /etc/init.d/shadowsocks restart; fi
* 12 * * * /usr/bin/updatednsmasq

计划任务说明:

每半小时检查shadowsocks-libev 客户端,如果退出就自动重启
每天中午12点更新dnsmasq配置文件
使用

opkg update
opkg install libstdcpp

wget http://update.adbyby.com/download/7620n.tar.gz
tar zxvf 7620n.tar.gz
mv /root/bin /usr/bin/adbyby
cd /usr/bin/adbyby
chmod 777 adbyby
/usr/bin/adbyby/adbyby &

路由设置透明代理

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118

加入启动项

sed -i '$i\/usr/bin/adbyby/adbyby &' /etc/rc.local
sed -i '$i\iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118' /etc/rc.local

也可以创建一个启动脚本

vi /etc/init.d/adbyby

#!/bin/sh /etc/rc.common
START=99
STOP=99
APP='adbyby'
start() {
ulimit -n 4096
config_load "$APP"
local enable

config_get enabled config enabled
[ "$enabled" = '1' ] && {
   service_start /usr/bin/adbyby/adbyby &
   iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118
}
}
stop() {
service_stop ps | grep "adbyby" | grep -v 'grep' | awk '{print $1}' | xargs kill -9
iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118
}

加执行权限

chmod +x /etc/init.d/adbyby
/etc/init.d/adbyby enable

保存后就在web界面的菜单: »管理 »系统 »启动项 就可以看到adbyby 然后点击“启用”就ok了。

基于OPENWRT 配置自动穿墙路由器》上有一条评论

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用 * 标注