用 pdnsd 和 dnsmasq 解决 dns 污染 安装 opkg update opkg install pdnsd 编辑配置 vim /etc/pdnsd.conf global { server_ip = 192.168.4.1 ; # 这里改成路由 LAN 口 IP query_method = tcp_only ; # 只使用TCP } server { root_server = on; # 设置为 on 后, 就代替系统默认的 dns 了. ip = 8.8.8.8, 8.8.4.4; # 这里是上级 dns 的 ip 地址 uptest = none; # 不去检测 dns 是否无效. } 配置 dnsmasq 对于 openwrt 来说默认就安装好了 dnsmasq 由于 pdnsd 和 dnsmasq 默认用的都是 53 端口,所以先修改 dnsmasq 的端口到 5555 由于我对配置不熟悉,所以我打开了 luci , 网络——DHCP/DNS——服务器设置——高级设置 ,在 DNS 服务器端口 由 53 改为 5555 ,保存&应用 。为了避免改了dnsmasq的dns服务端口后,连接路由器设备无法正常从dhcp服务获取dns服务器地址,还要一步额外的配置,在 网络——接口——LAN——DHCP服务器 ,选高级设置 ,DHCP-选项 填入:6,192.168.4.1 192.168.4.1 是你路由 LAN 口 IP ,根据自己情况写 然后编辑文件 nano /etc/dnsmasq.conf 在最后一行加入 conf-dir=/etc/dnsmasq.d 新建目录 mkdir /etc/dnsmasq.d/ 然后在建一个 gfw.conf 文件, 把需要解析的域名代理给 pdnsd 就可以了nano /etc/dnsmasq.d/gfw.conf # google server=/.google.com/127.0.0.1#53 server=/.gstatic.com/127.0.0.1#53 server=/.googleusercontent.com/127.0.0.1#53 server=/.appspot.com/127.0.0.1#53 server=/.googlecode.com/127.0.0.1#53 server=/.googleapis.com/127.0.0.1#53 server=/.gmail.com/127.0.0.1#53 server=/.google-analytics.com/127.0.0.1#53 server=/.youtube.com/127.0.0.1#53 server=/.blogspot.com/127.0.0.1#53 server=/.blogger.com/127.0.0.1#53 之后重启 dnsmasq 服务 /etc/init.d/dnsmasq restart 启动路由器上的 pdnsd 服务 /etc/init.d/pdnsd enable /etc/init.d/pdnsd start 安装 dig sudo apt-get update sudo apt-get install dnsutils |