密切相关如何在 18.04 上设置本地通配符(127.0.0.1)域解析?。以下是我在 19.10 上按照早期 18.04 的说明所做的操作:
- 安装 dnsmasq
apt install dnsmasq
- 编辑 NetworkManager.conf
# head -3 /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq
(这似乎不起作用[稍后将 dns=dnsmasq 添加到 resolv.conf。)
3.
# sudo ln -sf /var/run/NetworkManager/resolv.conf /etc/resolv.conf
# ls -l /etc/resolv.conf
lrwxrwxrwx 1 root 35 Oct 18 20:59 /etc/resolv.conf -> /var/run/NetworkManager/resolv.conf
- 制定了一些规则
# more /etc/NetworkManager/dnsmasq.d/*
::::::::::::::
/etc/NetworkManager/dnsmasq.d/dnsmasq-localhost.conf
::::::::::::::
address=/localhost.com/127.0.0.1
::::::::::::::
/etc/NetworkManager/dnsmasq.d/dotlocal-wildcard.conf
::::::::::::::
address=/.local/127.0.0.1
::::::::::::::
/etc/NetworkManager/dnsmasq.d/example.com-wildcard.conf
::::::::::::::
address=/.example.com/127.0.0.1
- 确保运行 dnsmasq 并重新加载
systemctl disable systemd-resolved
systemctl stop systemd-resolved
systemctl start dnsmasq
systemctl reload NetworkManager
- 检查谁在听
# sudo netstat -tulpn | grep dns
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 949/dnsmasq
tcp6 0 0 :::53 :::* LISTEN 949/dnsmasq
udp 0 0 0.0.0.0:53 0.0.0.0:* 949/dnsmasq
udp6 0 0 :::53 :::* 949/dnsmasq
- 并观察到我的失败
# dig example.com +short
93.184.216.34
# dig example.local +short
# host example.local
Host example.local not found: 3(NXDOMAIN)
问题 1:步骤 3 是否应该以resolv.conf
某种方式获取dns=dnsmask
或(nameserver 127.0.0.1
)进行查询?如果我手动将这些添加到中resolve.conf
,我可以(有时)将example.com
和解析any.example.com
为所需的 127.0.0.1。
问题 2:为什么‘example.local’甚至无法按预期解析为 127.0.0.1?
谢谢您的建议。
PS:遗憾的是,对 127.0.0.1 的通配符匹配不是标准解析的一部分,而是需要 dnsmasq。
答案1
尝试将其作为顶行resolv.conf
:
nameserver 127.0.0.1
并尝试安装named
。