如何使用 bind9 设置 OpenVPN 服务器作为私有 DNS 服务器?

如何使用 bind9 设置 OpenVPN 服务器作为私有 DNS 服务器?

最近,我使用 OpenVPN 服务器和 Bind9 设置 VPN 节点以防止 DNS 泄漏,但在使用 Bind9 时遇到了问题。设置 OpenVPN 服务器大部分都很容易,但显然 bind9 有点棘手,所以我就遇到了问题。当我在客户端计算机上使用“dig”命令时,它运行良好 - ping 正常,没有延迟或任何问题,客户端获取所需的 IP 地址。以下是此请求从服务器端显示的样子(客户端上的命令:dig @10.8.0.1 ya.ru):

15:30:47.728737 IP 10.8.0.78.54465 > 10.8.0.1.domain: 18060+ [1au] A? ya.ru. (34)
15:30:47.729432 IP 10.8.0.1.domain > 10.8.0.78.54465: 18060 1/2/5 A 87.250.250.242 (201)

但是如果我使用 wget 或 curl - 我会遇到长时间的延迟,bind 无法正常工作,并且在超时(据说是 5 秒)后,客户端会向 ISP 服务器发送 DNS 请求,从而导致 DNS 泄漏。当客户端执行“wget youtube.com”时,服务器上会发生以下情况:

15:35:55.463780 IP 10.8.0.78.33465 > 10.0.8.1.domain: 9299+ A? youtube.com. (29)
15:35:55.463932 IP 10.8.0.78.33465 > 10.0.8.1.domain: 47722+ AAAA? youtube.com. (29)
15:36:02.336465 IP 10.8.0.78.46473 > 10.0.8.1.domain: 47830+ A? www.youtube.com. (33)
15:36:02.336828 IP 10.8.0.78.46473 > 10.0.8.1.domain: 41320+ AAAA? www.youtube.com. (33)

我注意到的主要区别是,在这种情况下,请求仅从客户端发送到服务器,而不是像第一个示例中那样来回发送。当客户端尝试在浏览器中加载页面时也会发生同样的事情。DNS 解析需要 5 秒以上,并且毕竟使用 isp 的 DNS 服务器。我不确定是 OpenVPN 还是 Bind9 配置错误,我尝试了很多不同的变化,但仍然没有进展。操作系统 - Debian 10。我还尝试了有防火墙和没有防火墙的情况。如果您遇到相同或相关的问题,并且您知道可能是什么问题 - 请帮助,或者至少将我引导到可能的错误。谢谢!

以下是配置文件:

OpenVPN服务器:

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key  
dh dh2048.pem
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 10.0.8.1"
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist /var/log/openvpn/ipp.txt
keepalive 10 120
tls-auth ta.key 0 
cipher AES-256-CBC
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
verb 3
explicit-exit-notify 1
management 127.0.0.1 7505
ccd-exclusive
client-config-dir /etc/openvpn/ccd

OpenVPN 客户端:

client
dev tun
proto udp
remote 123.123.123.123 1194 # IP ноды
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
remote-cert-tls server
tls-auth ta.key 1
cipher AES-256-CBC
auth SHA256
key-direction 1
verb 3

Bind9 配置:

acl vpn {10.8.0.0/24; 127.0.0.1;};
options {
  directory "/var/cache/bind";
  allow-query {vpn;};
  max-ncache-ttl 3600;
  max-cache-ttl 3600;
  dnssec-validation no;
  auth-nxdomain no;
  listen-on-v6 {none;};
};

相关内容