From ab5f25c9915b48e55a85b91e8211d6670589df00 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 25 Aug 2025 18:19:19 +0800 Subject: [PATCH] fix: deploy gai.conf if both v4 and v6 present (#23160) Co-authored-by: Qiu Jian --- pkg/hostman/guestfs/fsdriver/linux.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/hostman/guestfs/fsdriver/linux.go b/pkg/hostman/guestfs/fsdriver/linux.go index 9aca3bf271..640a669313 100644 --- a/pkg/hostman/guestfs/fsdriver/linux.go +++ b/pkg/hostman/guestfs/fsdriver/linux.go @@ -458,6 +458,26 @@ func (l *sLinuxRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*ty log.Errorf("rootFs.GenerateSshHostKeys fail %s", err) } } + { + // deploy /etc/gai.conf if both IPv4 and IPv6 are enabled + v4Enabled := false + v6Enabled := false + for _, nic := range nics { + if nic.Ip != "" { + v4Enabled = true + } + if nic.Ip6 != "" { + v6Enabled = true + } + if v4Enabled && v6Enabled { + // prefer IPv4 over IPv6 by default of /etc/gai.conf not present + if !rootFs.Exists("/etc/gai.conf", false) { + rootFs.FilePutContents("/etc/gai.conf", "precedence ::ffff:0:0/96 100\n", false, false) + } + break + } + } + } return nil }