I think this is working as intended. When you add a name to /etc/hosts, you're telling local resolvers to inhibit address lookups for the name. So if you define it as IPv4-only, then IPv4-only is what you get.
I understand your point, but I disagree. I think when an IPv4 host is added to a host file the system is being instructed to use that IP as a preferred IP. However if an IPv6 address is specifically requested and there isn't one present in the hosts file, but is via DNS, then it should be expected that the request will return the IPv6 address available via DNS.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
What operating system and processor architecture are you using (
What did you do?
Add a IPv4 entry to the host file for example.com (do not add an IPv6 entry):
Run the following code:
What did you expect to see?
When explicitly requesting an IPv6 address you should be returned an IPv6 if available via DNS even if there is an IPv4 address in the hosts file.
What did you see instead?
No addresses were returned:
This is because the request is passed from ipsock without specifying the desired address family:
Then dnsclient_unix performs a lookup against hosts, it finds an entry (IPv4 in this case) then returns this:
ipsock then filters the returned addresses and only returns the IPs of the requested family:
The text was updated successfully, but these errors were encountered: