傻瓜级两种 OpenWrt 能简单实现无污染 DNS 的方式 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
OpenWrt 是一个专门面向嵌入式设备的 Linux 发行版。你可以将 OpenWrt 支持的型号的嵌入式设备,比如各种路由器上的系统,换成一个有更多可能性可以折腾的 Linux 系统。
OpenWrt 官方网站
strp
V2EX    OpenWrt

傻瓜级两种 OpenWrt 能简单实现无污染 DNS 的方式

  •  
  •   strp 2023-02-25 05:52:00 +08:00 4542 次点击
    这是一个创建于 1037 天前的主题,其中的信息可能已经有所发展或是发生改变。

    第一种是通过自带的 DNSMASQ:

    1. 网络
    2. DHCP 和 DNS
    3. DNS 转发
    4. 填入 101.6.6.6**#**5353 注意是#而不是 @
    5. 保存并应用,然后就可以了,默认 OpenWrt 都会劫持局域网内所有 UDP/TCP 53 端口,所以你的客户端不需要额外做些什么。

    第二种是从 OpenWrt 抄的防火墙规则,新的 OpenWrt 应该默认都有不过是全局劫持而且是转发到本地的 DNSMASQ:

    只需要稍加修改只劫持指定的 IP 就可以正常使用,你可以按需修改。 你要先删除自带的两条全局劫持 53 端口的规则。 这样做的作用是劫持客户端到 8.8.8.8/8.8.4.4/1.1.1.1/1.0.0.1 这些 IP 地址的 53 端口到 101.6.6.6#5353 所以你要去手动设置 DHCP Client 的 DNS 为以上 IP ,你也可以劫持其它 IP ,比如 8.9.6.4,但是这样就会太 Confuse 了,不推荐,你也可以让 OpenWrt 设置 DHCP Client 获取到的 DNS 为一下 IP ,下面会讲到。

    iptables -t nat -A PREROUTING -p udp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 1.0.0.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 1.0.0.1--dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 

    以上内容加到:

    1. 网络
    2. 防火墙
    3. 自定义规则

    如果你想把 TCP 的 53 也劫持了,那你可以用下面的:

    iptables -t nat -A PREROUTING -p udp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p udp -d 1.0.0.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p udp -d 1.0.0.1--dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 53 iptables -t nat -A PREROUTING -p tcp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p tcp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p tcp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 iptables -t nat -A PREROUTING -p tcp -d 1.0.0.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp -d 8.8.8.8 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp -d 8.8.4.4 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp -d 1.1.1.1 --dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 5353 [ -n "$(command -v ip6tables)" ] && ip6tables -t nat -A PREROUTING -p tcp -d 1.0.0.1--dport 53 -j REDIRECT --to-destination 101.6.6.6 --to-ports 53 

    让 DHCP Client 自动获取不同的 DNS 服务器:

    1. Network
    2. LAN Edit
    3. DHCP Section
    4. Advanced Options
    5. DHCP Options
    6. 填入 6,8.8.8.8,8.4.4.4
    7. 保存并应用

    弊端:

    你国内访问的所有带 CDN 的网站估计都会获取到教育网内的服务器,高峰期可能会导致访问不稳定,并且有人反馈虎牙等直播平台只允许教育网网内用户访问教育网网内服务器资源,所以这个方法不能说天衣无缝,顶顶用还是可以的。如果你实在没有办法在局域网内搭建另一个比如 Overture 这样具有分流功能的 DNS Server ,而且也不会写 init.d/Overture 配置文件也不想折腾其他东西,虽然说不会写 init.d 可以 screen这是一个不错的解决方案

    3 条回复    2023-06-21 09:30:05 +08:00
    Cooky
        1
    Cooky  
       2023-02-25 18:00:55 +08:00
    打破零回复,但是只是 mark
    wangweitung
        2
    wangweitung  
       2023-02-25 23:03:15 +08:00 via Android
    折腾过 adgurdhome ,用来做 dns 过滤,但总会有各种各样的问题。
    但最后还是放弃了。用回默认。。。
    strp
        3
    strp  
    OP
       2023-06-21 09:30:05 +08:00
    An alternative way forwarding local port 5335 to 198.18.0.1:53, replace 198.18.0.1 as your destination and replace 198.18.0.2 as your gateway IP (in this case your OpenWrt)
    5335 is used by default in ShadowsocksR Plus+, only way to route the UDP DNS requests without force using TCP or send to proxy.

    iptables -t nat -A PREROUTING -p tcp --dport 5335 -j DNAT --to-destination 198.18.0.1:53
    iptables -t nat -A POSTROUTING -p tcp -d 198.18.0.1 --dport 53 -j SNAT --to-source 198.18.0.2
    iptables -t nat -A PREROUTING -p udp --dport 5335 -j DNAT --to-destination 198.18.0.1:53
    iptables -t nat -A POSTROUTING -p udp -d 198.18.0.1 --dport 53 -j SNAT --to-source 198.18.0.2
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2804 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 12:43 PVG 20:43 LAX 04:43 JFK 07:43
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86