dnsmasq 无法将 .local 地址指向 127.0.0.1

use*_*159 4 networking dns dnsmasq ubuntu

我想获取.local地址(例如 test.local)指向127.0.0.1但它不起作用。我在最新的 Ubuntu 上。在 /etc/NetworkManager/NetworkManager.conf 我注释掉dns=dnsmasq然后做了sudo service network-manager restart

然后我安装了 dnsmasq 并将 a 添加address=/local/127.0.0.1到 /etc/dnsmasq.d/mycustomfile 然后做了sudo service dnsmasq restart. 除了我提到的,我没有做其他改变。

但是当我访问 test.local 时,它没有解析为 127.0.0.1,对该 .local 地址执行 ping 操作也不成功。也许内容/etc/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
nameserver 222.11.22.36
nameserver 222.11.22.37
Run Code Online (Sandbox Code Playgroud)

这是我不作为守护进程运行 dnsmasq 时的输出:

$ sudo dnsmasq --no-daemon     
dnsmasq: started, version 2.68 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
dnsmasq: reading /etc/resolv.conf
dnsmasq: using nameserver 222.11.22.37#53
dnsmasq: using nameserver 222.11.22.36#53
dnsmasq: read /etc/hosts - 9 addresses
Run Code Online (Sandbox Code Playgroud)

当 dnsmasq 运行时 /etc/resolv.conf 自动更新(并在 dnsmasq 停止时恢复到上面的条目):

# 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
nameserver 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

和这个:

$ sudo nslookup test.local 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   test.local
Address: 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

但是仍然对本地主机执行 ping 操作不起作用。

我需要做什么才能让 dnsmasq 工作来解析 .local 地址?

小智 8

看起来 dnsmasq 启动正确。您应该测试 dnsmasq 是否正确使用nslookup test.local 127.0.0.1.

为确保系统使用 dnsmasq,您必须更新/etc/resolv.confnameserver 127.0.0.1用作第一个选项。

您还可以在 dnsmasq 上使用 custo 上游解析器配置--resolv-file=/etc/resolv.conf.dnsmasq


小智 7

local 似乎是某种保留关键字,至少在 Ubuntu 上是这样:

  • address=/local/127.0.0.1 ——没用。
  • address=/loc/127.0.0.1 ——作品。