Score:0

Windows ping chooses IPv4 address

cn flag

When I run ping myserver I can see two DNS queries in Wireshark, one for A and one for AAAA. Both get answered with the IPv4 and IPv6 address respectively and ping starts pinging the IPv4 address. If I run ping -6 it uses the IPv6 address.

I thought IPv6 is preferred if both are available, why does it choose IPv4?

I have an IPv6 address and a default IPv6 route with the link-local address of my router. That said, the internet is not reachable through this route, but ping (or the DNS resolver) doesn't know that, does it?

Jaromanda X avatar
ru flag
does the system you are pinging from have a routable ipv6?
user1686 avatar
fr flag
and if it does, how similar are the source and destination addresses? do they share a common prefix? are any of them ULA or site-local? "source address selection" (netsh int ipv6 show prefixpolicy) may be preferring native ipv4 over e.g. ULA ipv6 or "6to4" ipv6
cn flag
Yes, the system I'm pinging has a normal internet IPv6 address and can be pinged from locations with IPv6 connectivity just fine.
Score:0
jp flag

The documentation for the ping command does not specify defaults nor precedence; just that either IPv4 or IPv6 could be forced when the target is a hostname.

Parameter  Description
/4 Specifies IPv4 used to ping. This parameter is not required to identify the target host with an IPv4 address. It is only required to identify the target host by name.
/6 Specifies IPv6 used to ping. This parameter is not required to identify the target host with an IPv6 address. It is only required to identify the target host by name.

The precedence comes from the prefix policies, e.g.,

C:\> netsh interface ipv6 show prefixpolicies

Precedence Label Prefix
---------- ----- ------
        50     0 ::1/128
        40     1 ::/0
        35     4 ::ffff:0:0/96
        30     2 2002::/16
         5     5 2001::/32
         3    13 fc00::/7
         1    11 fec0::/10
         1    12 3ffe::/16
         1     3 ::/96

If the ::/0 has higher precedence than the ::ffff:0:0/96 (IPv4), then IPv6 is preferred, and vice versa.

From the article "Guidance for configuring IPv6 in Windows for advanced users" you can also see that there is a registry key for configuring IPv6. The table is shortened.

The IPv6 functionality can be configured by modifying the following registry key:

Location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\
Name: DisabledComponents
Type: REG_DWORD
Min Value: 0x00 (default value)
Max Value: 0xFF (IPv6 disabled)

IPv6 Functionality  Registry value and comments
Prefer IPv4 over IPv6 Decimal 32
Hexadecimal 0x20
Binary xx1x xxxx

Recommended instead of disabling IPv6.
Prefer IPv6 over IPv4 Binary xx0x xxxx
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.