OpenWRT 路由器的 dnsmasq 设置阻止局域网名称解析?

OpenWRT 路由器的 dnsmasq 设置阻止局域网名称解析?

我有一台 15.05 版 OpenWRT 路由器,它是本地网络的成员。此网络有自己的 DHCP 和 DNS 服务器,dnsmasq 应该会自动使用这些服务器进行域名解析。但是,局域网成员的主机名并未通过 dnsmasq 进行解析。

我尝试过/etc/init.d/dnsmasq stop让这些名称在路由器上解析。但是,当连接到路由器时,这会停止我的笔记本电脑上的所有域名解析。

我希望 dnsmasq 不会从其结果中过滤本地域名,并让它使用正确的 DNS 服务器(我相信它会这样做),或者通过将上游 DNS 服务器 IP 地址传递给路由器的客户端来找到一种不使用 dnsmasq 的方法。(我更希望不要对 DNS 服务器 IP 地址进行硬编码,以便路由器可以在其他环境中使用而无需重新配置。)

我禁用了下面的一些选项,因为它们确保“......对这些本地主机名(和反向查找)的请求永远不会转发到上游 DNS 服务器。”[1]然而这并没有解决我的 dnsmasq 问题。

root@wrt0:~# cat /etc/config/dhcp

config dnsmasq
        #option domainneeded '1'
        option domainneeded '0'
        #option boguspriv '1'
        option boguspriv '0'
        option filterwin2k '0'
        #option localise_queries '1'
        option localise_queries '0'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        #option expandhosts '1'
        option expandhosts '0'
        option nonegcache '0'
        #option authoritative '1'
        option authoritative '0'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option localservice '1'

...

root@wrt0:~# cat /etc/config/network

...
config interface 'lan'
        option ifname 'eth1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '10.0.2.1'
        option netmask '255.255.255.0'

...

root@wrt0:~# cat /etc/resolv.conf 
search lan
nameserver 127.0.0.1

root@wrt0:~# cat /tmp/resolv.conf.auto 
# Interface wan
nameserver 192.168.0.10
nameserver 192.168.0.25
search office.website.org
search website.org

使用 dnsqmasq 解析本地名称时,解析失败:

root@wrt0:~# nslookup abc.office.website.org
Server:    127.0.0.1
Address 1: 127.0.0.1 localhost

nslookup: can't resolve 'abc.office.website.org': Name or service not known

当绕过 dnsmasq 时,解析工作正常:

root@wrt0:~# nslookup abc.office.website.org 192.168.0.10
Server:    192.168.0.10
Address 1: 192.168.0.10 resolver.office.website.org

Name:      abc.office.website.org
Address 1: 192.168.0.32 abc.office.website.org

dnsmasq 顺利地查找面向互联网的服务器:

root@wrt0:~# nslookup abc.website.org
Server:    127.0.0.1
Address 1: 127.0.0.1 localhost

Name:      abc.website.org
Address 1: 208.xxx.xxx.xxx xyz.website.org

您对如何绕过 dnsmasq 的过滤或完全绕过 dnsmasq 有什么想法吗?谢谢!:D

答案1

一种解决方案是禁用 dnsmasq 并更改dhcp 'lan'的部分/etc/config/dhcp,尽管它需要特定于网络的配置:

root@wrt0:~# /etc/init.d/dnsmasq stop
root@wrt0:~# /etc/init.d/dnsmasq disable

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option dhcpv4 'server'
        option ra 'server'
        list   dns '192.168.0.10'
        list   dns '192.168.0.25'
        list   domain 'office.website.org'
        list   domain 'website.org'
        list   domain 'othersite.org'

实现类似结果的另一种方法是使用 dnsmasq 并添加一个选项/etc/dnsmasq.conf

dhcp-option=6, 192.168.0.10, 192.168.0.25

但是,如何使用 dnsmasq 设置多个域尚不清楚search

不幸的是,如果路由器在不同的网络上使用或者 DNS IP 地址发生变化,则这两种方法的设置都需要编辑,因此这不是完美的答案。

答案2

首先,你应该真正升级到当前版本(18.X)或最新版本(17.XX):https://wiki.openwrt.org/de/doc/howto/generic.sysupgrade

如果我理解正确的话,DNS 和 DHCP 服务器在您的网络中是不同的设备吗?如果是这样,应该domainneeded打开,并且您应该在 /etc/hosts 中设置 DNS 到 IP 的映射。阅读第一部分文档以获得进一步的提示。

相关内容