openwrt解决dns污染pdnsd+dnsmasq解决DNS污染

2020-07-24
0评论
/
2500阅读
爱搜啊

网域服务器缓存污染(DNS cache pollution),又称域名服务器缓存投毒(DNS cache poisoning),是指一些刻意制造或无意中制造出来的域名服务器数据包,把域名指往不正确的IP地址。

openwrt解决dns污染

一般来说,在互联网上都有可信赖的网域服务器,但为减低网络上的流量压力,一般的域名服务器都会把从上游的域名服务器获得的解析记录暂存起来,待下次有其他机器要求解析域名时,可以立即提供服务。

一旦有关网域的局域域名服务器的缓存受到污染,就会把网域内的计算机导引往错误的服务器或服务器的网址。

OpenWRT安装pdnsd

主要用来解决污染问题,在openwrt上直接找到pdnsd包安装就可以了。

opkg update
opkg install pdnsd

安装好以后还需要修改 /etc/pdnsd.conf,其主要配置如下:

global {
# debug = on;          # 调试模式, 日志会写入 /var/pdnsd/pdnsd.debug
perm_cache=1024;
cache_dir=“/var/pdnsd”;
run_as=“nobody”;
server_port = 1053;    # 使用 1053 作为 dns 端口, 默认是 53
server_ip = any;
status_ctl = on;
query_method=tcp_only; # 最重要的配置, 只使用 tcp 查询上级 dns
min_ttl=15m;
max_ttl=1w;
timeout=10;
}
server {
label= “wido”;           # 这个随便写
ip = ${UPSTREAM_DNS_IP}; # 这里为上级 dns 的 ip 地址
root_server = on;        # 设置为 on 后, 就代替系统默认的 dns 了.
uptest = none;           # 不去检测 dns 是否无效.
}
source {
owner=localhost;
# serve_aliases=on;
file=“/etc/hosts”;
}
rr {
name=localhost;
reverse=on;
a=127.0.0.1;
owner=localhost;
soa=localhost,root.localhost,42,86400,900,86400,86400;
}

其中的${UPSTREAM_DNS_IP} # 这里为上级 dns 的 ip 地址此处,需要设置成,支持 TCP dns 查询的服务器。

可以用 8.8.8.8 这个 google 的 dns 但不是很推荐, 主要是他返回的 ip 虽然没污染, 但这个 ip 很可能也是被封的. 最好是那些 台湾, 日本, 或者美国东部的 dns. 目前大陆默认走的就是香港的 google 服务器, 所以香港的 dns 也不予考虑。

当然最好的方案还是,如果你自己在海外有 VPS 那就在服务器上装个 pdnsd 来做 dns 服务器吧。

可以用命令

dig @8.8.8.8 +tcp www.google.com

来做测试, 不过也遇到过 +tcp 可以访问但实际无法用 pdnsd 连接的情况具体原因未知. 我这是自己服务器搭了 pdnsd 解决的。

在找到可用的 dns 后, 接着修改回 pdnsd.conf 文件后输入

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

启动路由器上的 pdnsd 服务之后就可以通过命令 (@192.168.2.1 根据自己家的网络情况改)

dig @192.168.2.1 –p 1053 www.google.com

来检测是否已配置好, 还是不行的话, 可以尝试开启 pdnsd.conf 的 dubug 模式看详细的日志, 配合pdnsd-ctl help 来做进一步处理。

Dnsmasq

本来指望 pdnsd 把 dnsmasq 的任务也一并解决的, 不过研究后发现他并不能将特殊的域名交给特殊的 dns 处理, 所以这部分功能还需要交给 dnsmasq。

对于 openwrt 来说默认就安装好了 dnsmasq, 所以这里只需要简单的编辑 /etc/dnsmasq.conf, 再最后加入

conf–dir=/etc/dnsmasq.d

让 dnsmasq 会去加载 /etc/dnsmasq.d 目录下所有的配置。

然后在建一个 /etc/dnsmasq.d/gfw.conf 这样的文件, 把需要进化的域名代理给 pdnsd 就可以了, 例如:

# google
server=/.google.com/127.0.0.1#1053
server=/.gstatic.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=/.blogspot.com/127.0.0.1#1053
server=/.blogger.com/127.0.0.1#1053

之后重启 dnsmasq 服务

/etc/init.d/dnsmasq restart

一般来说这样折腾以后想访问的一般都可以应该就可以访问了, 当然也可以按这个写法自己加其他的域名。具体的还得是满足 ip 没被封且关键字不被过滤(https) 的网站才行。


本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


于2020-07-24发布