DNS通配符和/etc/resolv.conf问题

我通过google.comsearch,但无法find答案…所以我问了这里。

这就是问题:

我在PC上build立了一个DNStesting环境,其主机名是gamepc

DNS服务器(bind9)有一个通配符logging:

 * IN A 192.168.0.1 

而/etc/resolv.conf文件有一个条目:

 domain bogus. nameserver 127.0.0.1 

所以当我ping somehost它会像下面这样返回:

 PING somehost.bogus (192.168.0.1) 56(84) bytes of data. 64 bytes from gamepc.bogus (192.168.0.1): icmp_req=1 ttl=64 time=0.042 ms ... 

而当我平google.com它会返回像:

 PING google.com (74.125.71.99) 56(84) bytes of data. 64 bytes from hx-in-f99.1e100.net (74.125.71.99): icmp_req=1 ttl=51 time=68.0 ms ... 

到目前为止,一切都很好。 但是,如果我ping一些不存在的域,例如sldfjsldjflksdjf.com它仍然会返回如下:

 PING sldfjsldjflksdjf.com.bogus (192.168.0.1) 56(84) bytes of data. 64 bytes from gamepc.bogus (192.168.0.1): icmp_req=1 ttl=64 time=0.043 ms ... 

预期的结果应该是:

 ping: unknown host sldfjslkdfjlksdjfklsdjf.com 

我可以想像这是怎么发生的。 首先parsing器尝试sldfjslkdfjlksdjfklsdjf.com但得到一个NXDOMAIN响应。 然后它追加域部分,并再次尝试sldfjslkdfjlksdjfklsdjf.com.bogus 。 这次主机名与DNS服务器中的通配符logging匹配并返回192.168.0.1

有没有人有同样的问题? 你是怎么解决的?

非常感谢您的阅读!

有没有人有同样的问题?

每个人都有这个问题。 这是大多数DNS客户端库的标准部分 。 它被称为域searchpathDNSsearchpathDNS委托

你是怎么解决的?

通过使用完全合格的域名 ,我希望他们。 您没有使用FQDN。

浏览器不使用FQDN来parsing主机域名

这是您第一次提到WWW浏览器。 你在这个问题中没有提到它。 WWW浏览器是古怪的,不仅仅是因为它们有两个,有时甚至更多的域searchpath。 正是出于这个原因,人们使用URL中完全合格的域名。 如果你要设置你的DNS客户端库,使得它的searchpath机制成功地将名字映射到这样的地址,你也必须这样做。 这是您selectsearchpath和匹配整个子树中所有内容的通配符的结果。 必须考虑使用通配符。

man resolv.conf

 domain Local domain name. Most queries for names within this domain can use short names relative to the local domain. If no domain entry is present, the domain is determined from the local hostname returned by gethostname(2); the domain part is taken to be everything after the first '.'. Finally, if the hostname does not contain a domain part, the root domain is assumed. search Search list for host-name lookup. The search list is normally determined from the local domain name; by default, it contains only the local domain name. (...) 

所以,如果你查询sldfjslkdfjlksdjfklsdjf然后绑定发现没有匹配的logging,所以你的parsing器尝试sldfjslkdfjlksdjfklsdjf.bogus ,这反过来返回一个地址。

如果你ping sldfjslkdfjlksdjfklsdjf. (注意尾随点),你应该可以(即查找失败)。 尾部的圆点表示您提供了主机的FQDN,因此不应尝试域后缀。

我不认为你可以真正解决这个问题,因为你的DNSconfiguration中有通配符。

当不使用通配符的时候,你会得到错误信息,但是通配符和你的resolv.conf选项会将所有未知的信息parsing到你的域中。