vi /etc/sysctl.conf
# 将net.ipv4.ip_forward=0更改为net.ipv4.ip_forward=1
sysctl -p
DNS的解析方案为 resolve.conf ==> dnsmasq ==> cdns
- 安装
opkg install xxx.ipk
- 配置
{
"global": {
// run as daemon
"daemon": true,
// where to send log to: syslog:daemon, stderr, file:/path/file
"log": "syslog:daemon",
// pid file
//"pidfile": "/var/run/cdns.pid",
// enable or disable debug info
"log_debug": false
},
"cdns": {
// local server listen address and port
"listen_ip": "127.0.0.1",
"listen_port": 1053,
// Timeout for each DNS request
"timeout": 2,
// List of upstream DNS servers
"servers": [
{
"ip_port": "203.80.96.10:53"
},
{
"ip_port": "8.8.8.8:53"
}
]
}
}
???
- dnsmasq的配置
vi /etc/dhcpcd.conf
# 文件末尾加上两行(去掉注释)
# ------
# listen-address=127.0.0.1
# conf-dir=/etc/dnsmasq.d/,*.conf
# ------
# 最后一行指定dnsmasq的解析规则目录,这里只解析被墙的域名,
# 参考https://gist.github.com/lanceliao/85cd3fcf1303dba2498c的脚本生成一份污染域名列表放到该目录下,列表自带ipset规则
- resolve.conf的配置
由于dnsmas监听127.0.0.1的53端口,会先使用dnsmasq解析被污染域名,不在规则内的域名使用114解析
由于cdns返回正确的解析,并且dnsmasq已经将1053转发到53端口,直接用127.0.0.1即可?
vi /etc/resolv.conf
---
# Generated by resolvconf
domain lan
nameserver 127.0.0.1
这个文件可能被dhcpd改掉,所以保护一下
vi /etc/dhcpcd.conf
#最末尾加上下面这行
nohook resolv.conf
设成只读以防万一:chattr +i /etc/resolv.conf
- DNS整体测试
systemctl start dnsmasq
systemctl start pdnsd
ping一下facebook(这里测试的是dnsmasq的53标准端口),查一下结果的ip如果正常就没问题
-
编写shadowsocks启动和停止脚本
shadowsocks.sh
,这个脚本将gfwlist的列表域名使用shadowsocks转发。dnsmasq的配置在/etc/dnsmasq.d
目录下,由于gfwlist里面没有google的域名,我们另加一个配置文件:server=/.google.com.hk/127.0.0.1#1053 ipset=/.google.com.hk/gfwlist server=/.google.com/127.0.0.1#1053 ipset=/.google.com/gfwlist server=/.google.jp/127.0.0.1#1053 ipset=/.google.jp/gfwlist server=/.google.co.jp/127.0.0.1#1053 ipset=/.google.co.jp/gfwlist server=/.google.co.uk/127.0.0.1#1053 ipset=/.google.co.uk/gfwlist server=/.amazonaws.com/127.0.0.1#1053 ipset=/.amazonaws.com/gfwlist
-
编写和启动shadowsocks服务
shadowsocks.service
-
参考