如何为从 dhcp 租约生成的域设置 dnsmasq 通配符 cname?

如何为从 dhcp 租约生成的域设置 dnsmasq 通配符 cname?

我有一台启用了自动 DHCP 域的 OpenWRT 路由器。这样,对于主机 example-host,我会自动将 example-host.lan 的 A 记录设置为 192.168.1.2。

我正在尝试为 *.example-host.lan 设置通配符 cname。为此,dnsmasq 似乎需要成为该域的权威 dns 服务器。

下面是我尝试之前的配置。有了它,当 ping example-host.lan 时,它会按预期解析为 192.168.1.2。

dhcp-authoritative
domain-needed
localise-queries
read-ethers
enable-ubus
expand-hosts
bind-dynamic
local-service
domain=lan
server=/lan/
dhcp-leasefile=/tmp/dhcp.leases
resolv-file=/tmp/resolv.conf.auto
dhcp-broadcast=tag:needs-broadcast
addn-hosts=/tmp/hosts
conf-dir=/tmp/dnsmasq.d
user=dnsmasq
group=dnsmasq

dhcp-host=<mac address>,192.168.1.2,example-host,12h


dhcp-ignore-names=tag:dhcp_bogus_hostname
conf-file=/usr/share/dnsmasq/dhcpbogushostname.conf


bogus-priv
conf-file=/usr/share/dnsmasq/rfc6761.conf
dhcp-range=set:lan,192.168.1.100,192.168.1.249,255.255.255.0,12h
no-dhcp-interface=eth1.2
dhcp-range=set:guest,192.168.2.100,192.168.2.249,255.255.255.0,12h

在安装 dnsmasq-full 之后(因为默认软件包未编译所需的功能),我尝试将这些行添加到开头,并使用不同的 IP 范围组合、eth0 或 eth1 等。无论我尝试什么,添加这些行时,都不会生成 cname,并且 A 记录也会消失。

cname=*.example-host.lan,example-host.lan
auth-server=example-host.lan,eth1
interface-name=example-host.lan,eth1
auth-zone=example-host.lan,192.168.0.0/16,eth1

我认为这个问题的出现只是因为我对 Dnsmasq 缺乏了解,而且它是一个庞大的程序,其手册页对我来说看起来像是用外星语言编写的……您知道我在这里可能做错了什么吗?更好的是,是否有一个简单易懂的解释来解释这一切?

答案1

我相信使用 cname 需要在 /etc/hosts 中定义简单名称。

--cname=<cname>,[<cname>,]<target>[,<TTL>]
       Return  a  CNAME  record  which indicates that <cname> is really <target>. There are significant limitations on the target; it must be a DNS name which is known to dnsmasq from /etc/hosts (or
       additional hosts files), from DHCP, from --interface-name or from another --cname.  If the target does not satisfy this criteria, the whole cname is ignored. The cname must be unique, but  it
       is permissible to have more than one cname pointing to the same target. Indeed it's possible to declare multiple cnames to a target in a single line, like so: --cname=cname1,cname2,target

相关内容