在Ubuntu20.04上安装Bind 9.18 启用DoH
DoH的意义在于将域名解析的请求由原来的网络层直接提升到了浏览器应用层。
网络层的问题是DoT使用853的端口,很容易被封锁,而DoH使用443端口,一般不会被封锁。
在进行域名查询的时候,浏览器和安全域名服务提供者之间是没有第三方的,第三方无法获取浏览器想要查询的域名。只有自己和安全浏览器提供者之间知道你访问的主站是什么,至于具体访问了什么页面也是不可知的。
但是DoH的速度上面并不见的比普通的UDP/TCP 53的DNS查询快。
只是这种查询在浏览器的多线程的配合下,加载复杂页面的时候,可能有突然一起加载完成的情况,感觉比较快。
过程
- sudo add-apt-repository ppa
/bind-dev - sudo apt-get update
- sudo apt install bind9
- configure /etc/bind/named.conf.options
tls mytls{ key-file "/etc/bind/private.pem"; cert-file "/etc/bind/cert.pem"; };
http local-http-server { endpoints { "/dns-query"; }; };
options { directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want // to talk to, you may need to fix the firewall to allow multiple // ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable // nameservers, you probably want to use them as forwarders. // Uncomment the following block, and insert the addresses replacing // the all-0's placeholder.
// forwarders { // 1.1.1.1; // 8.8.8.8; // 9.9.9.9; // };
//======================================================================== // If BIND logs error messages about the root key being expired, // you will need to update your keys. See https://www.isc.org/bind-keys //======================================================================== recursion yes; allow-recursion { any; }; listen-on { 10.214.23.216; }; listen-on port 443 tls mytls http local-http-server { 10.214.23.216; }; listen-on port 8899 tls none http local-http-server { 10.214.23.216; }; //listen-on-v6 port 443 tls mytls http local-http-server { any; }; //listen-on-v6 { any; }; dnssec-validation auto;};
logging {
channel transfers { file "/var/log/bind/transfers" versions 3 size 10M; print-time yes; severity info; }; channel notify { file "/var/log/bind/notify" versions 3 size 10M; print-time yes; severity info; }; channel dnssec { file "/var/log/bind/dnssec" versions 3 size 10M; print-time yes; severity info; }; channel query { file "/var/log/bind/query" versions 5 size 10M; print-time yes; severity info; }; channel general { file "/var/log/bind/general" versions 3 size 10M; print-time yes; severity info; }; channel slog { syslog security; severity info; }; category xfer-out { transfers; slog; }; category xfer-in { transfers; slog; }; category notify { notify; };
category lame-servers { general; }; category config { general; }; category default { general; }; category security { general; slog; }; category dnssec { dnssec; };
category queries { query; };};- 检查和启动服务
named-checkconf /etc/bind/named.confsudo systemctl restart bind9sudo systemctl enable bind9sudo systemctl status bind9journalctl -xe 如果有错误信息的话,用这个检查。- 对bind log文件夹设定权限
sudo mkdir -p /var/log/bindsudo chown bind/var/log/bind- 对apparmor进行设定
vi /etc/apparmor.d/usr.sbin.named# 增加以下内容 /etc/bind/** r, /var/lib/bind/** rw, /var/lib/bind/ rw, /var/cache/bind/** lrw, /var/cache/bind/ rw, /var/log/bind/** rw, /var/log/bind/ rw,- restart apparmor 服务 systemctl restart apparmor
- 检查https查询: dig +https @dohserver.examplecn www.baidu.com A
- 检查query log文件: cat /var/log/bind/query
- 配置浏览器安全dns: https://dohserver.examplecn/dns-query
- 测试是否可以正常访问网站
- 检查query log是否正常
总结
这里的证书和私钥是已有的,不需要自己生成。
服务器使用的是Ubuntu20.04,安装了bind9,使用了apparmor。
服务器的主机名为dohserver.examplecn,域名为examplecn。
因为这个examplecn的域名由我管理,所以设定了dohserver.examplecn的A记录为10.214.23.216,内网可以解析即可。
listen-on port 8899 tls none http local-http-server { 10.214.23.216; };
这句的目的是在前端有一台nginx的服务器,在nginx的服务器上面做证书卸载。
下面是nginx的配置文件:
upstream doh { server 10.214.23.216:8899; #keepalive 8;}
server { listen 443 ssl http2; #ssl on; #ssl_certificate /etc/nginx/ssl/server_1.cer; ssl_certificate /etc/nginx/ssl/server.cer; #ssl_certificate_key /etc/nginx/ssl/server_1.key; ssl_certificate_key /etc/nginx/ssl/server.key; server_name doh.examplecn; access_log /var/log/nginx/doh.log;
location /dns-query { grpc_pass grpc://doh; } }浏览器在使用安全dns服务后,将请求发送给nginx服务器,nginx服务器再将请求发送给bind9服务器,bind服务器给出响应后,将响应发送给nginx服务器,nginx服务器将响应发送给浏览器。
因为我的这台bind服务器是测试段,只有我和少量人可以使用,但是用nginx后,就可以发布到全体了。也就是这个事情。
如果使用bind的src进行安装的话,需要的依赖必须装好,这个比较烦。但是目前centos还没有相应的package,所以先放着吧。
root@dohserver:/var/log/bind# named -vBIND 9.18.0-2+ubuntu20.04.1+isc+1-Ubuntu (Stable Release) <id:>