V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tyhunter
V2EX  ›  问与答

openwrt 上如何解决 DNS 污染的问题

  •  
  •   tyhunter · 2015-12-27 21:19:24 +08:00 · 10071 次点击
    这是一个创建于 3013 天前的主题,其中的信息可能已经有所发展或是发生改变。
    14 条回复    2015-12-28 14:25:14 +08:00
    BSD
        1
    BSD  
       2015-12-27 21:26:43 +08:00   ❤️ 1
    装 dnscrypt 。。。不过解析速度很慢,反正我的 MT7620a ,域名第一次查询时要等近 20 秒,用的是法国的节点。
    tyhunter
        2
    tyhunter  
    OP
       2015-12-27 21:28:05 +08:00
    @BSD 我的想法是,有没有办法像电脑上根据 PAC 来判断,就是列表内的地址走国外干净 DNS ,列表外的走 114 ,阿里之类的国内 DNS
    xmh51
        3
    xmh51  
       2015-12-27 21:32:17 +08:00   ❤️ 1
    @tyhunter 有啊。已经有实现案例了。 dnsmasq-full
    haruhi
        4
    haruhi  
       2015-12-27 21:33:17 +08:00   ❤️ 1
    影袜 UDP 转发非 53 端口 DNS ,然后安装 ChinaDNS ,设置好国内和转发的 DNS ,就可以根据路由表走
    datocp
        5
    datocp  
       2015-12-27 21:36:12 +08:00   ❤️ 1
    不习惯本地 isp 以外的 dns ,用 chinadns 上游使用本地 dns 时会出现两种情况,敏感域名返回国内 百度或者阿里的 ip ,不敏感域名仅是封锁 ip ,这种情况 chinadns 失效了。

    使用 ipset 载入 g f w list 黑名单也是有些问题的,比如 android 下的 google play 看不到图片,有部分 ip 明显连接有问题并没通过 vpn 。

    基于上面的原因,现在 g f w list 的域名通过 vpn 连接 8.8.8.8 连接
    for i in `cat /gfwb`;do echo server=/$i/8.8.8.8>>/etc/dnsmasq.conf;done

    建立 ipset nethash ,将所有国内的路由段写入
    ipset test outwall4 192.168.8.253
    if [ $? -eq 1 ];then ipset -N outwall4 nethash; for IP in $(cat /da/ocserv/cn1.lst);do ipset -A outwall4 $IP;done;fi

    所有非国内 ip 段全部走 vpn ,安逸了
    iptables -t mangle -I PREROUTING 2 -m mark --mark 0x0/0xff00 -m set ! --match-set outwall4 dst -j MARK --set-xmark 0xfe00/0xff00
    iptables -t mangle -I OUTPUT -m mark --mark 0x0/0xff00 -m set ! --match-set outwall4 dst -j MARK --set-xmark 0xfe00/0xff00
    tyhunter
        6
    tyhunter  
    OP
       2015-12-27 21:45:50 +08:00
    @xmh51 感谢,我去看看
    @haruhi 我试过这方法,但好像没效果....
    @datocp 是通过 openwork 自身防火墙来判断吗?
    lanlanlan
        7
    lanlanlan  
       2015-12-27 21:50:16 +08:00
    datocp
        8
    datocp  
       2015-12-27 21:57:05 +08:00
    国内外路由表可以自己提取,

    然后在获得的 cn.lst 再添加这些地址,包括 vpsip 。这样就根据国内 /外 路由段为依据分流,因为目前看起来访问国外网站都一样的慢。还有一个好处不必维护不在 g f w list 上的一些屏蔽 ip 的域名。

    # Ignore LANs and some other reserved addresses.
    # See http://en.wikipedia.org/wiki/Reserved_IP_addresses#Reserved_IPv4_addresses
    # and http://tools.ietf.org/html/rfc5735 for full list of reserved networks.
    vpsip1/32
    vpsip2/32
    0.0.0.0/8
    10.0.0.0/8
    127.0.0.0/8
    169.254.0.0/16
    172.16.0.0/12
    192.168.0.0/16
    224.0.0.0/4
    240.0.0.0/4


    #!/bin/sh
    rm -rf /tmp/ip;mkdir /tmp/ip;cd /tmp/ip
    wget http://www.ipdeny.com/ipblocks/data/countries/all-zones.tar.gz

    tar zvfx all-zones.tar.gz
    sort -V -u cn.zone>cn.lst
    rm -rf cn.zone
    find -name "*.zone" -exec 'cat' {} \; > uncn.tmp
    sort -V -u uncn.tmp>uncn.lst

    rm -rf *.zone
    JackBlack2006
        9
    JackBlack2006  
       2015-12-27 21:59:01 +08:00
    楼上哪位这一笔笔添加不累么,开个 sftp 然后 pc 上编辑好了上传,上万条规则不是问题
    bazingaterry
        10
    bazingaterry  
       2015-12-27 22:26:33 +08:00
    直接 443 走 opendns
    lee015
        11
    lee015  
       2015-12-28 08:34:15 +08:00 via Android
    我现在是 dnsmasq+pdnsd+ss
    1. dnsmasq 把 gfwlist 地址 server 设为 pdnsd ,并加 ipset 。
    2. pdnsd 上游 tcp opendns 5353 端口。
    3. 防火墙规则里加一条 iptables 规则, gfwset 里转发到 ss 。

    gfwlist 生成 dnsmasq 配置文件有个 Python 脚本,改了下让它额外支持一个自定义列表,很方便。
    xmh51
        12
    xmh51  
       2015-12-28 10:29:51 +08:00
    @JackBlack2006 我一般只添加重要域名,规则过多会造成运行缓慢?(有人说过)。
    hero18688
        13
    hero18688  
       2015-12-28 11:30:31 +08:00
    像长城宽带这种 udp 极其不稳定的网络怎么办呢 只能 tcp 查询 dns
    chinni
        14
    chinni  
       2015-12-28 14:25:14 +08:00
    比较懒的办法就是 dnsmasq 默认用 OpenDNS 的 443 端口解析,然后 在 /etc/dnsmasq.d 下放中国域名的配置, 然后用 国内运营商 dns 解析. 列表在 github 上有维护.
    https://github.com/felixonmars/dnsmasq-china-list

    然后 配置文件的关键语句就是
    server=208.67.222.222#443
    server=208.67.220.220#443
    conf-dir=/etc/dnsmasq.d

    其他的看需求添加就可以了 比如 dhcp 之类的....
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5415 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:48 · PVG 16:48 · LAX 01:48 · JFK 04:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.