我需要在“/etc/resolv.conf”中配置超过 3 个 DNS 服务器。
据 man 说,它不受支持,所以我必须重新编译 glibc
Up to MAXNS (currently 3) name servers may be listed, one per line. If there are multiple servers,
the resolver library queries them in the order listed. If no nameserver entries are present, the default is to use the name server on the local machine. (The algorithm used is to try a name server, and if the query times out, try the next, until out of name servers, then repeat trying all name servers until a maximum number of retries are performed.)
我改变了常数
MAXNS
在 resolv/bits/types/res_state.h
我编译如下:mkdir glibc-build
cd glibc-build
../glibc-(version of glibc)/configure --prefix=/usr/local/lib/glibc-testing --with-tls --enable-add-ons=nptl
make
make install
我尝试 ping 一些站点,并在 Wireshark 的帮助下尝试查看它正在处理哪些服务器。服务器仍然寻址前三个地址。我还看到文件
/usr/include/x86_64-linux-gnu/bits/types/res_state.h
没有改变。问题是什么?
最佳答案
--prefix=/usr/local/lib/glibc-testing
构建 glibc 以安装到该目录层次结构中,因此它将与系统的其余部分隔离。这是一件好事,因为 MAXNS
更改是一个非常剧烈的 ABI 中断,因此需要重建相当多的程序。 make install
通常在中途崩溃 --prefix=/usr
,留下一个不再可用的系统。上游 glibc 也不支持 Debian 样式的多架构目录( /usr/include/x86_64-linux-gnu
和 /usr/include
)。
无论如何,要以适合包含在上游 glibc 中的方式增加受支持的名称服务器的数量,需要执行以下步骤:
struct __res_state
中的每个名称服务器文件描述符(nssocks
数组)在 resolv/res_send.c
. stub 解析器只保持一个套接字打开,因此无论如何使用数组是没有意义的。 struct resolv_conf
除了搜索列表条目之外,还可以跟踪名称服务器。 _res
中的名称服务器更改(应用程序可以直接写入 _res
,在这种情况下应该使用这些名称服务器)。这与搜索列表代码平行。 resolv/res_send.c
中的实际DNS客户端代码使用所有名称服务器(不仅仅是 struct __res_state
中的那些)。 这是一个重要的贡献,所以它需要 FSF copyright assignment .
关于ubuntu - ubuntu中超过3个DNS服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64047757/