V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
icharm
V2EX  ›  macOS

使用 PF 防火墙拦截 DNS 查询,避免电信 DNS 劫持

  •  
  •   icharm · 2016-05-29 12:44:38 +08:00 · 2439 次点击
    这是一个创建于 2880 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我是电信校园客户,使用 MAC 版的天翼校园客户端(v 1.3)拨号上网:
    拨号成功后会新建一个 ppp0 的连接:
    sh-3.2# ifconfig
    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 ::1 prefixlen 128
    inet 127.0.0.1 netmask 0xff000000
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    nd6 options=1<PERFORMNUD>
    gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
    stf0: flags=0<> mtu 1280
    en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=6b<RXCSUM,TXCSUM,VLAN_HWTAGGING,TSO4,TSO6>
    ether f0:76:1c:22:31:d0
    inet6 fe80::f276:1cff:fe22:31d0%en0 prefixlen 64 scopeid 0x4
    inet 10.163.253.195 netmask 0xffff0000 broadcast 10.163.255.255
    nd6 options=1<PERFORMNUD>
    media: autoselect (100baseTX <full-duplex,flow-control>)
    status: active
    ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1480
    inet 222.94.242.51 --> 222.94.242.1 netmask 0xffffff00

    现在我需要挂 VPN 爬墙,问题出现了,电信 DNS 劫持了域名解析。而我现在没办法修改这个 ppp0 接口的 DNS 服务器。在设置-网络中,根本看不到这个连接。
    我已经将本地连接的 DNS 服务器设置为 8.8.8.8 和 114.114.114.114 。但是还是被劫持了。
    对 ppp0 接口抓包:
    发现在使用 218.1.135.1 的 DNS 服务器,而且使用的 DNS 服务器有很多,比如说,我重启一下,使用的 DNS 服务器又换成新的了,我遇到比较常见的有 218.2.2.2 , 218.4.4.4 。
    本来想尝试修改天翼客户端的本地配置文件,但是没找到有关的配置文件。
    于是想到了使用防火墙进行 DNS 查询的拦截,然后转发给 114.114.114.114 。
    但是又遇到了问题:
    我新建了 PF 规则文件 /etc/pf.anchors/dns
    内容如下:
    rdr pass on ppp0 inet proto udp from any to any port = 53 -> 114.114.114.114 port 53
    rdr pass on ppp0 inet proto tcp from any to any port = 53 -> 114.114.114.114 port 53

    然后使用 pfctl 测试了这个规则
    sh-3.2# pfctl -vnf pf.anchors/dns
    pfctl: Use of -f option, could result in flushing of rules
    present in the main ruleset added by the system at startup.
    See /etc/pf.conf for further details.

    rdr pass on ppp0 inet proto udp from any to any port = 53 -> 114.114.114.114 port 53
    rdr pass on ppp0 inet proto tcp from any to any port = 53 -> 114.114.114.114 port 53

    然后在 /etc.pf.conf 中引入了这个规则:
    scrub-anchor "com.apple/*"
    nat-anchor "com.apple/*"
    rdr-anchor "com.apple/*"
    rdr-anchor "http-forwarding"
    dummynet-anchor "com.apple/*"
    anchor "com.apple/*"
    load anchor "com.apple" from "/etc/pf.anchors/com.apple"
    load anchor "http-forwarding" from "/etc/pf.anchors/dns"

    最后使用 pfctl 加载规则提示:
    sh-3.2# pfctl -f pf.conf
    pfctl: Use of -f option, could result in flushing of rules
    present in the main ruleset added by the system at startup.
    See /etc/pf.conf for further details.

    No ALTQ support in kernel
    ALTQ related functions disabled

    重启之后并没有生效,依旧是是使用 DNS 的服务器。怎么办求解!
    OSX 版本为 10.11.3(EI caption)
    icharm
        1
    icharm  
    OP
       2016-05-30 18:14:38 +08:00
    求助啊啊啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5273 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 85ms · UTC 01:20 · PVG 09:20 · LAX 18:20 · JFK 21:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.