我使用 dnsmasq 设置了一个 DNS 服务器,但似乎无法正常工作。网络延迟高达数百毫秒。
PING [server] ([server]) 56(84) bytes of data.
64 bytes from [server]: icmp_seq=1 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=2 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=3 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=4 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=5 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=6 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=7 ttl=50 time=583 ms
64 bytes from [server]: icmp_seq=8 ttl=50 time=583 ms
然后很快我发现使用默认解析器就可以了systemd-resolved
。通过检查日志,我得到了下面的消息:
Jul 27 13:32:53 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:53 dnsmasq[3780]: forwarded ntp.ubuntu.com to 127.0.0.53
Jul 27 13:32:53 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:53 dnsmasq[3780]: forwarded ntp.ubuntu.com to 127.0.0.53
[countless records repeating these above...]
Jul 27 13:32:53 dnsmasq[3780]: Maximum number of concurrent DNS queries reached (max: 150)
Jul 27 13:32:54 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:54 dnsmasq[3780]: forwarded ntp.ubuntu.com to 127.0.0.53
[...]
[probably the sigterm was sent here?]
Jul 27 13:32:57 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:57 dnsmasq[3780]: forwarded ntp.ubuntu.com to 127.0.0.53
Jul 27 13:32:58 dnsmasq[3780]: no servers found in /run/dnsmasq/resolv.conf, will retry
Jul 27 13:32:58 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:58 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:58 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:58 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:58 dnsmasq[3780]: query[A] ntp.ubuntu.com from 127.0.0.1
Jul 27 13:32:58 dnsmasq[3780]: exiting on receipt of SIGTERM
那么..请问如何解决这个让我抓狂的问题呢:(
dnsmasq.conf 的内容如下:
strict-order
resolv-file=/etc/resolv.conf.dnsmasq
listen-address=0.0.0.0
server=/aliyuncs.com/100.100.2.136
server=/aliyuncs.com/100.100.2.138
server=/*.cn/100.100.2.136
server=/*.cn/100.100.2.138
bogus-nxdomain=100.100.2.136
bogus-nxdomain=100.100.2.138
log-queries
log-facility=/var/log/dnsmasq/dnsmasq.log
log-async=50
#EOF
以及 resolv.conf.dnsmasq:
nameserver 100.100.2.136
nameserver 100.100.2.138
nameserver 208.67.222.123
nameserver 208.67.220.123
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 1.2.4.8
nameserver 210.2.4.8
nameserver 208.67.222.222
nameserver 208.67.220.220
解析.conf:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
options timeout:2 attempts:3 rotate single-request-reopen
答案1
已解决。只需bind-interfaces
在 dnsmasq.conf 中添加一个条目并启动两个 DNS 解析器即可。
并确保 systemd-resolved 监听 127.0.0.53:53。
[resolv.conf]
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.1
options timeout:2 attempts:3 rotate single-request-reopen
[netstat -apn | grep 53]
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 10122/dnsmasq
tcp 0 0 172.18.129.180:53 0.0.0.0:* LISTEN 10122/dnsmasq
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 10066/systemd-resolved
udp 0 0 127.0.0.1:53 0.0.0.0:* 10122/dnsmasq
udp 0 0 172.18.129.180:53 0.0.0.0:* 10122/dnsmasq
udp 0 0 127.0.0.53:53 0.0.0.0:* 10066/systemd-resolved
unix 3 [ ] STREAM CONNECTED 590253 1121/master
[dnsmasq.log]
Jul 28 12:31:57 dnsmasq[10122]: query[A] www.stackexchange.com from 127.0.0.1
Jul 28 12:31:57 dnsmasq[10122]: forwarded www.stackexchange.com to 127.0.0.53
Jul 28 12:31:57 dnsmasq[10122]: reply www.stackexchange.com is <CNAME>
Jul 28 12:31:57 dnsmasq[10122]: reply stackexchange.com is 151.101.129.69
Jul 28 12:31:57 dnsmasq[10122]: reply stackexchange.com is 151.101.193.69
Jul 28 12:31:57 dnsmasq[10122]: reply stackexchange.com is 151.101.65.69
Jul 28 12:31:57 dnsmasq[10122]: reply stackexchange.com is 151.101.1.69
[nslookup www.stackexchange.com]
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
www.stackexchange.com canonical name = stackexchange.com.
Name: stackexchange.com
Address: 151.101.193.69
Name: stackexchange.com
Address: 151.101.1.69
Name: stackexchange.com
Address: 151.101.65.69
Name: stackexchange.com
Address: 151.101.129.69