我是 Ubuntu/Linux 的初学者,所以我想知道是否有任何方法可以强制 Ubuntu 在解析名称时首选 IPv4 或 IPv6(例如:google.com 有 ipv4 和 ipv6 地址。是否有任何设置允许我说当某些应用程序要求该名称时应该优先使用 IPv6 而不是 IPv4?)
谢谢。
答案1
您可以在/etc/gai.conf
文件中更改它。
从man gai.conf
:
DESCRIPTION
A call to getaddrinfo(3) might return multiple answers. According to
RFC 3484 these answers must be sorted so that the answer with the high‐
est success rate is first in the list. The RFC provides an algorithm
for the sorting. The static rules are not always adequate, though.
For this reason, the RFC also requires that system administrators
should have the possibility to dynamically change the sorting. For the
glibc implementation, this can be achieved with the /etc/gai.conf file.
Each line in the configuration file consists of a keyword and its pa‐
rameters. White spaces in any place are ignored. Lines starting with
'#' are comments and are ignored.
该文件中有一部分注释行可供您更改。其中有一行特别说明以下内容:
# For sites which prefer IPv4 connections change the last line to
#
#precedence ::ffff:0:0/96 100
这意味着如果您希望 IPv4 优先于 IPv6,那么您基本上只需取消注释上面的行,并将最后一行更改为注释所述的内容。