54

DNSCrypt简明教程 - Jiajun的编程随想

 4 years ago
source link: https://jiajunhuang.com/articles/2019_10_31-dnscrypt.md.html?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

DNSCrypt简明教程

我们输入 jiajunhuang.com 之后,浏览器是需要将 jiajunhuang.com 翻译成IP,然后才能建立TCP连接的。而将域名翻译成IP地址, 就是DNS服务器的事情,但是有一个小问题,DNS是明文的。

也就是说,尽管你使用了HTTPS,由于在建立TLS连接之前,你得先查询域名所对应的IP,因此,还是可以通过监控你的DNS来推测你准备 访问什么流量,更坏一点的情况,可以给你伪造一个响应,返回错误的地址,这种情况就叫做“DNS污染”。

所以我们需要使用DNSCrypt来加密我们的DNS通信:

$ sudo pacman -S dnscrypt-proxy

然后编辑 /etc/dnscrypt-proxy/dnscrypt-proxy.toml,将最后的 static 改成你想要的DNS服务器,你可以在 这里 选择你喜欢的(一般来说就是你试试访问快的),然后填进去,例如:

[static]
  [static.'cloudflare']
  stamp = 'sdns://AgcAAAAAAAAABzEuMC4wLjGgENk8mGSlIfMGXMOlIlCcKvq7AVgcrZxtjon911-ep0cg63Ul-I8NlFj4GplQGb_TTLiczclX57DvMV8Q-JdjgRgSZG5zLmNsb3VkZmxhcmUuY29tCi9kbnMtcXVlcnk'

接着启动 dnscrypt-proxy

$ sudo systemctl start dnscrypt-proxy
$ sudo systemctl enable dnscrypt-proxy

到这里还不行,因为你没有配置使用该DNS。如果你使用的是NetworkManager,那么就编辑文件 /etc/NetworkManager/conf.d/rc-manager.conf

[main]
rc-manager=resolvconf

然后编辑 /etc/resolvconf.conf

# Configuration for resolvconf(8)
# See resolvconf.conf(5) for details

resolv_conf=/etc/resolv.conf
# If you run a local name server, you should uncomment the below line and
# configure your subscribers configuration files below.
name_servers=127.0.0.1

接着重启 NetworkManager

$ sudo systemctl restart NetworkManager

如果你使用了libvirt来管理虚拟机,你会发现虚拟机会断网,重启host即可。

内网DNS咋办?

使用 dnscrypt-proxy 固然爽,但是有个小问题,就是如果是在公司里,很有可能就有内网DNS,这就很蛋疼了, dnscrypt-proxy 有一个解决方案,那就是使用 cloaking rules,编辑 /etc/dnscrypt-proxy/dnscrypt-proxy.toml,把 cloaking_rules 这一行 注释掉,然后编辑 /etc/dnscrypt-proxy/cloaking-rules.txt 这个文件,在后面添加你的DNS,例如:

# my customized dns
www.one-domain.com x.x.x.x
*.your-domain.com x.x.x.x

其实我想要方案是匹配域名,然后把这些域名的DNS指向另一个DNS,这样会方便些,不过似乎 dnscrypt-proxy 还不支持。

还有一个方案就是把 fallback_resolver 改成公司所提供的DNS。


动态规划民科教程 Golang 分布式异步任务队列 Machinery 教程 使用geohash完成地理距离计算 2018年就要到了,这一年都做了什么呢? 算法导论阅读笔记 --- 排序算法 Git HTTPS 如何保存密码 短链系统的实现 程序员修炼之道 阅读笔记 Python开发实践经验 Golang实现平滑重启(优雅重启) traefik 教程 Web开发简介系列 Nginx作为TCP/UDP的负载均衡 Web开发系列(十):事务和锁 Web开发系列(十一):数据库扩展



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK