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

2016-05-29 12:44:38 +08:00
 icharm
我是电信校园客户,使用 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)
2452 次点击
所在节点    macOS
1 条回复
icharm
2016-05-30 18:14:38 +08:00
求助啊啊啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/282005

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX