2019-9-27 14:37:21 [显示全部楼层]
5110浏览
查看: 5110|回复: 0

[教程] 广告、追踪快走开,Pi-Hole及智能网络系统

[复制链接]

前言

原创文章,转载引用请务必注明链接,水平有限,如有疏漏,欢迎指正。
真的是不用不知道,一用吓一跳,各种软件,各个网页无时无刻都在追踪着你,安卓上是data.mistat.xiaomi.com,苹果上是e.crashlytics.com,普通网页的话就是谷歌了。尤其是小米,大约每分钟就发送一次数据。因为我最近搞得软硬件要点记略已经有一万多字了,本文仅摘取其中一小部分叙述,所以将做极大精简,其他内容后续慢慢整理出来,欢迎回复交流。

项目目的

使用Pi-Hole拦截网络追踪器和阻断广告,并通过sower作为上游DNS服务器实现基于DNS的智能上网系统(地图)。
uKSf0J.png

硬件需求

  1. PLAN A
    • 树莓派3B
    • 实际使用过程中发现受限于性能,还是有些问题,看了性能评分4代树莓派应该会好很多。
  2. PLAN B
    最近了解到了软路由相关的知识,跃跃欲试,最终卖掉了手头的Espressobin板子,DIY了一套家境贫寒版小服务器,倒腾了一下,使用感觉极好。自从自己组装了一台台式电脑,真的是打开了新世界的大门。
    • i5-3470T Ivy Bridge CPU,TDP 35W
    • Intel DQ77KB Thin-ITX主板
    • id-cooling is20 超薄散热风扇
    • “航嘉”19v 90w DC电源
    • 建兴64GB mSATA SSD 拆机
    • 协德 8G“海力士”颗粒DDR3L 1600低压内存
    • 西数500G 2.5寸 蓝盘
    • 立人E-i5 like 小机箱
      后来买了俩4010的风扇,结果发现太小了,还不如我的usb'散热风扇效果好,单is20风扇~56℃,4010风扇~52℃,usb散热风扇(应该是6020)~42℃,效果明显,要知道发热是耗电大户。

主板选择

ServerBuilds网站上推荐itx板就是dq77kb,intel出品,之前用过intel Galileo和Edison开发板对它的做工印象深刻。这板子优点多多,神板不解释。之前大船靠岸价格~200元,现在炒到340+了,被我咸鱼捡漏一块,包括电源、半高档版、is20风扇计240元,修板花30元。

CPU选择

查了很多资料,1155接口的我中意三款低TDP的:e3 1220L v1(无内置显卡,好在dq77支持AMT),e3 1260L和i5 3470T(3代)。最终选择3470T,了解了很多东西,TDP并不代表最终功耗。

Notes on low-TDP CPUs
The  Thermal  Design  Power  (TDP)  figure  for  CPUs  is  not  a  realistic  measure  of  power
consumption, but of peak consumption. Realistic workloads are bursty, not a continuous stream
of strenuous calculations, which means that faster processors can finish more quickly and thus
more quickly enter a lower power state.
Low-TDP CPUs, designated by a T for Core i3 and L for Xeon E3, use the exact same physical
processor as their regular counterparts – the only difference being an artificially low limit on
TDP. In practice, this means that the low-TDP version will be limited to slower clocks in order to
remain within its tighter thermal envelope. The realistic expectation is that the integral of power
over time will be similar for both cases, but some benchmarks have shown a significant power
consumption advantage for regular-TDP processors.
Finally, it should be noted that idle power will be exactly the same, minus variations between
units. It is theoretically possible to bin the units that exhibit better low-power behavior for low-
TDP usage, but there’s little evidence that suggests such binning takes place.
In conclusion, low-TDP CPUs only make sense in scenarios where either a heat dissipation or
power distribution constraint exists. A properly-designed server should suffer from neither of
these.
——Via FreeNAS Community Hardware Guide 2016-10 Edition Revision 1e

实际测下来也确实如此,完成同样的工作,TDP 35w的3470T要比TDP 20w不带内置gpu的1220l更省电。这里就不展开了,留在其他文章里讲。

软件组成

操作系统选择

对比了Exsi和Proxmox VE,选择后者,因为熟悉Linux,后者更加得心应手,优点多、性能好,当然缺点肯定也有。

网络服务组成

  • 高恪软路由系统——主路由,负责拨号
  • Debian 10 lxc容器系统——提供网络服务
    • Pi-hole——网络追踪阻断和广告过滤
    • Sower——智能上网系统
      uK9aIs.png

几点说明:

  1. 高恪做企业路由的,流量控制和ikuai差不多性能,但是占用资源比ikuai少。dq77有两个千兆网口,一个给高恪做wan,一个用来局域网共享的lan。
  2. 一般的方案是使用openwrt做二级路由,我这里需要更多自定义服务,所以选择的Debian做网络服务Provider Host。
  3. proxmox使用lxc容器而非docker容器,两者有些区别,后文再讲。

项目实现

安装配置Pi-Hole

只需一键命令:curl -sSL https://install.pi-hole.net | bash即可,更多安装方法参考这里,这样的话安装的都是最新版本。
浏览器打开LANip即可,稍等片刻,就可以看到小米
uKpK3V.png
uKpMcT.png
除此之外,windows10也号称隐私灾难。使用pihole的好处是,在路由器上设置dns之后,终端设备不需要额外操作。但是要设置在dhcp的dns里,因为高恪还有个dhcp代理。
uKpzb4.png
使用ss -atnup命令或netstat -lnp命令可以看到pihole使用dnsmasq占用53端口提供DNS服务,lighttpd占用80端口提供Web Interface。

Sower智能上网

马上就要给祖国过生日了,好开心!Sower项目地址:https://github.com/wweir/sower ,我不细讲了,实现透明很方便。

          request target servers
<-------------+              +------------->
              |              |
              |              |
      +------------server-------------+
      |       | relay service|        |
      | +-----+---------------------+ |
      | |                           | |
      | | parse http(s) target url  | |
      | |                           | |
      | +---------------------------+ |
      |     shadow service            |
      +--------^----------------------+
               |           request domain server
       quic / KCP / TCP         +---------->
               |                |
      +--------+---client+------+-----+
      |                  |            |
      |  shadow service  |            |
      |  relay service   |     dns    |
      |                  |   service  |
      |                  |            |
      |       127.0.0.1 or other      |
      |                  |            |
      +-^-----^----------+---^----^---+
        |     |              |    |
        |     |              |    |   +----->
http(s) proxy |   +----------+    |   |
              2   1               1   2
              +   +               +   +
         blocked request      normal request

主要有这么一个问题:建议更改80、443、53端口为其他不常用的,它需要占用53、443、80端口,有两个和Pi-Hole有冲突。

  • Q1:如何实现一台机器上两个DNS服务器不冲突?
    • 127.0.0.53 ? (system resolve)
    • 127.0.0.1@lo + lan_ip@eth0?
    • lan_ip_port1(sower) + lan_ip_53(pi-hole)?
  • Q2:谁做上游DNS服务器?
    • 两者谁监听lan 53都可以。
    • pi-hole支持自定义端口的上游服务器(i.e. 127.0.0.1#5353),sower只能读取/etc/resolv.conf里的系统dns服务器,而该文件不支持自定义端口的服务器。

改动如下:

pi-hole

##### Lighttpd ##### 80->1080 #####
sed -i 's/server.port                 = 80/server.port                 = 10080/g' /etc/lighttpd/lighttpd.conf

##### Pi-hole ##### Upstream DNS Servers #####
#option 1 在web-interface->settings->DNS->Upstream DNS Servers->Custom 1(IPv4)里添加LAN_ip#5353
#option 2 直接修改/etc/dnsmasq.d/01-pihole.conf->server=LAN_ip#5353

##### restart service ####
systemctl restart pihole-FTL
systemctl restart lighttpd
# 注意此时web interface地址为LAN_IP:10080/admin

uKiUde.png

Sower

sower默认占用三个端口,其中53可以修改,因为没有提供自定义端口功能,我们看看能否修改源码。这里搜索看看
uKANZT.png
OK,找到两处。怎么改呢?试试看。由于使用go language编写,我们需要下载go compile。具体参考官网教程:https://golang.org/doc/install

git clone https://github.com/wweir/sower && cd sower
go build
# opt:go clean
  1. 两个53都改成5353,编译运行失败
  2. 改第1个53为5353,失败
  3. 改第2个53为5353,成功!注意每次编译前都go clean一下

使用mv命令将编译好的sower替换原来的/usr/local/bin/sower

##### sower conf file ##### /usr/local/etc/sower.toml #####
# client_ip = "LAN_ip"
# dns_server = "114.114.114.114"
# 注意远程服务器地址、传输协议、密码等信息要写对,T-C-P、QUIC、K-C-P轮着用,有时候会崩。
systemctl restart sower-client
##### /etc/resolv.conf #####
# 改成nameserver "Lan_ip" ,注意换成你的ip地址

整个链路比较乱,我搞了两天弄明白的。最后看一下pi-hole和sower都正常了吗:ss -atnup,核对一下。
uKZ2wV.png

最终效果

连上路由器的设备无需任何配置,可以去广告追踪,访问谷哥等网站。其间学了很多知识,搞懂很多事,困难重重,大有“山重水复疑无路,柳暗花明又一村”之感,记录如上,行文混乱,凑合着看,哈哈。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail