Openwrt

网工不是白考的……买了一个牛逼的路由器,自然要发挥它的功效。
首先就是刷机成第三方固件Openwrt,dd-wrt的稳定性不佳,tomato的更新太缓慢。
故openwrt才是首选。

我用的是12.09的版本,目前感觉没啥问题。
改用14.07版本,一切正常

包管理命令

opkg update #更新源
opkg install 包名字 #安装某一个包

优先安装

opkg install luci-i18n-chinese #路由器中文界面
opkg install zile #编辑器,代替emacs,我不会用vim-_-
opkg install libncurses #zile必须品

opkg install wget #自带的wget不好用
opkg install unbound #解决dns污染,GFW升级已失效

(介于GFW在2014年的升级,以下文字已失效)

unbound配置文件解说
编辑unbound的配置文件/etc/unbound/unbound.conf,加入或找到相应的行去掉注释。

port: 5353
tcp-upstream: yes
forward-zone: 
        name: "." 
        forward-addr: 8.8.8.8
        forward-first: no

把unbound设置成开机启动,然后启动unbound

/etc/init.d/unbound enable
/etc/init.d/unbound start

dnsmasq配置文件解说(以下所有解说皆为空想)
/etc/dnsmasq.conf #主配置文件
/etc/config/dhcp #dhcp配置文件 不用修改
/tmp/etc/dnsmasq.conf #每次dnsmasq模块启动,自动生成的配置文件。

在第二个文件中,有这么一句

conf-file=/etc/dnsmasq.conf

于是,大胆假设conf-file为#include的意思。(真的是这样么?ovo)
以下所有脚本建立在此假设之上。

编辑/etc/dnsmasq.conf
末尾添加一句

conf-dir=/etc/dnsmasq.d

去广告、防dns污染脚本:make_dnsmasq_conf.sh
去广告效果不佳,因为中间层用了grep,有待改进

防dns部分用sed与awk两个天杀命令代理了脚本编程,各种暴力,各位看官自己分析吧XD

#!/bin/ash

local DNS_DIR=/etc/dnsmasq.d
local DNSMASQ_DNS_PULLTION=$DNS_DIR/dnsmasq.plt.conf
local DNSMASQ_DNS_ADS=$DNS_DIR/dnsmasq.ads.conf
local GFWLIST=/tmp/gfwlist.txt

logger WAN up script executing

# Anti Advertisement Begin
logger Downloading China Lazy List
echo '##Anti ADS' > $DNSMASQ_DNS_ADS
wget -O - http://adblock-chinalist.googlecode.com/svn/trunk/adblock-lazy.txt |
grep ^\|\|[^\*]*\^$ |
sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' >> $DNSMASQ_DNS_ADS
# Anti Advertisement End

# Anti DNS Pulltion Begin
logger Downloading GFW List
echo '##Anti DNS Pulltion' >$DNSMASQ_DNS_PULLTION
wget --no-check-certificate -O $GFWLIST https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
openssl base64 -d -in $GFWLIST | grep ^[a-z0-9\|\.] | grep -v -E '^[^\.]*$|[\*\%\[\/]|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'|sed -e 's:||::' -e 's:.::' | uniq | sed -e 's:^:server\=\/:' -e 's:$:/127\.0\.0\.1#5353:' >> $DNSMASQ_DNS_PULLTION

wget -O - http://smarthosts.googlecode.com/svn/trunk/hosts |
grep ^[0-9] |
awk '{print "address=/"$2"/"$1;}' >> $DNSMASQ_DNS_PULLTION
# Anti DNS Pulltion End

logger Restarting dnsmasq
/etc/init.d/dnsmasq reload