如何让 DNSMasq 为没有域的 Windows 主机提供 DNS 服务?

如何让 DNSMasq 为没有域的 Windows 主机提供 DNS 服务?

我有一台安装了 DNSMasq 的 Ubuntu 16.04 主机 (10.0.10.2),它是仅有的提供 DNS 服务,以及同一子网上的几个 Windows 主机,以及同一子网上的几个其他 Linux 主机。我的默认网关正在分发 DHCP 以及为 DNS 服务器分发 10.0.10.2。

Windows 机器没有定义 DNS 搜索后缀或域,但我希望它们能够解析我在 DNSMasq 服务器上的 /etc/hosts 中定义的主机,而无需指定域或搜索后缀,但是事实证明这很困难。根据 Wireshark 的说法,Windows 主机在执行 ping 或尝试导航到 Linux 主机上的 Web 服务时始终希望附加 .local。

我的/etc/hosts文件如下:

127.0.0.1 localhost
10.0.10.2 box-linux-0 box-linux-0.local
10.0.10.3 box-linux-1 box-linux-1.local
10.0.10.3 box-linux-2 box-linux-2.local
10.0.10.7 box-windows-0 box-windows-0.local
10.0.10.5 box-windows-1 box-windows-1.local

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

我的 DNSMasq 配置是:

strict-order
port=53
resolv-file=/etc/resolv.conf
log-queries
log-facility=/var/log/dnsmasq.log

我的 resolv.conf 是:

nameserver 127.0.0.1
nameserver 8.8.8.8

我是否缺少了一些东西来让 Windows 主机能够解析 box-linux-0、box-linux-1、box-linux-2?

答案1

您的 resolv.conf 不应具有外部 DNS 服务器,以确保 dnsmasq 解析所有 DNS 请求。改成:

nameserver 127.0.0.1

要允许解析外部 DNS 名称,请通过告诉 dnsmasq 使用某个外部 DNS 服务器来使用 dnsmasq 作为全局 DNS 服务器。添加到 DNSmasq 配置文件:

--server 直接指定上游服务器的IP地址。

server=8.8.8.8

要使 dnsmasq 只解析实际上可能是全局 dns 名称的名称,请添加到 DNSmasq 配置文件中:

# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv

要确保本地名称由 /etc/hosts 解析,请添加到 DNSmasq 文件:

# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
local=/local./

您可以尝试这个选项(可能有用也可能没用):

# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
expand-hosts

# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
domain=local

相关内容