禁用 resolv.conf 的搜索选项

Dov*_*der 5 centos resolv.conf

我们正在运行一个脚本,试图为一个研究项目解析数千个域。例如,我们遇到的问题是许多域无法解析foo.com。如果我们 pingfoo.com系统将查找foo.com. 如果这不能解决,它将查找foo.com.ourdomain.com. 它/etc/resolv.conf我们有:

# Generated by NetworkManager

search ourdomain.com
nameserver 8.8.8.8
nameserver 4.2.2.2
Run Code Online (Sandbox Code Playgroud)

由于我们设置了搜索设置,因此可以预期上述结果。如果我们将其更改为:

# Generated by NetworkManager

search ourdomain.net
nameserver 8.8.8.8
nameserver 4.2.2.2
Run Code Online (Sandbox Code Playgroud)

那么正如预期的那样,最后将使用 ourdomain.net 再次查询任何不可解析的查询。

我们遇到的问题是,如果我们完全删除搜索行,resolv.conf那么系统会返回使用 ourdomain.com 作为搜索。我们想要的是,如果 DNS 查找未解析为 NOT,则使用 WAS 设置的域resolv.conf(这也是框的域)进行查找。

Dov*_*der 6

解决方案是将 /etc/resolv.conf 中的搜索选项设置为:

search .
Run Code Online (Sandbox Code Playgroud)

所以 /etc/resolv.conf 看起来像。

search .
nameserver 8.8.8.8
nameserver 4.2.2.2
Run Code Online (Sandbox Code Playgroud)