我正在本地 Fedora 39 机器上dnsmasq
作为插件安装运行。NetworkManager
我所需要的dnsmasq
基本上是对hosts
可以按主题组织的其他文件的支持。
我的配置是:
/etc/dnsmasql.conf
:
user=dnsmasq
group=dnsmasq
interface=lo
bind-interfaces
conf-dir=/etc/NetworkManager/dnsmasq.d,*.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
/etc/NetworkManager/conf.d/00-use-dnsmasq.conf
[main]
dns=dnsmasq
/etc/NetworkManager/dnsmasq.d/00-add-hosts.conf
log-queries
no-hosts
addn-hosts=/etc/hosts.d
address=/development/127.0.0.1
/etc/hosts.d
是一个包含主机文件的目录,其中包含我想要“sinkhole”的条目:
0.0.0.0 1.example.com
0.0.0.0 2.example.com
...
dnsmasq
已启动并正在运行,我在进程中看到守护进程:
ps aux | grep dnsmasq
dnsmasq 61161 0.4 0.0 228096 4480 ? S 16:08 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/NetworkManager/dnsmasq.pid --listen-address=127.0.0.1 --cache-size=400 --clear-on-reload --conf-file=/dev/null --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d
我还在dnsmasq
调试日志中看到,主机文件/etc/hosts.d
也被读取:
Dec 30 16:18:40 fedora dnsmasq[61823]: chown of PID file /run/NetworkManager/dnsmasq.pid failed: Operation not permitted
Dec 30 16:18:40 fedora dnsmasq[61823]: DBus support enabled: connected to system bus
Dec 30 16:18:40 fedora dnsmasq[61823]: warning: no upstream servers configured
Dec 30 16:18:40 fedora dnsmasq[61823]: read /etc/hosts.d/private - 10 names
Dec 30 16:18:40 fedora dnsmasq[61823]: setting upstream servers from DBus
Dec 30 16:18:40 fedora dnsmasq[61823]: using nameserver 192.168.0.1#53(via wlp2s0)
但是,当我尝试从主机文件访问域时addn-hosts
,它们并没有0.0.0.0
按照我的预期解析。这些主机文件似乎被忽略。
另一方面,我添加到系统中的任何内容都会/etc/hosts
按预期工作。即使我no-hosts
在配置中显式使用了选项
dnsmasq
,并且我看到它已添加到守护程序调用中。
我还看到dnsmasq
使用了配置,因为该address=/development/127.0.0.1
行按预期工作:
$ ping -c 3 anything.development
PING anything.development (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.091 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.175 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.200 ms
只是addn-hosts
不知何故被忽略了。
这是我的/etc/resolv.conf
:
# Generated by NetworkManager
nameserver 127.0.0.1
options edns0 trust-ad
以前我认为这是systemd-resolved.service
干扰(因为它之前将 127.0.0.53 添加到我的resolv.conf
文件中),但现在我禁用了该服务:
systemctl status systemd-resolved.service
○ systemd-resolved.service - Network Name Resolution
Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; disabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: inactive (dead)
我不确定我的配置有什么问题。