-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: IPv6 lookup fails when IPv4 hosts entry is present #20327
Comments
/cc @mikioh @pmarks-net |
and @mdempsky |
I think this is working as intended. When you add a name to |
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. This is how python acts:
It is also how ssh, ping6 etc work:
|
So, according to That's pretty strange, but I can't argue with emulating whatever |
I'm fine with relaxing the existing behavior of Lookup API by following some external configuration such as nsswitch.conf.
Also fine to revisit the existing behavior. I can imagine it's pretty tough for people under some heterogenous environments to manage /etc/hosts, internal and public namespaces consistently. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?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:
https://github.com/golang/go/blob/master/src/net/ipsock.go#L259
Then dnsclient_unix performs a lookup against hosts, it finds an entry (IPv4 in this case) then returns this:
https://github.com/golang/go/blob/master/src/net/dnsclient_unix.go#L491-L494
ipsock then filters the returned addresses and only returns the IPs of the requested family:
https://github.com/golang/go/blob/master/src/net/ipsock.go#L265-L272
The text was updated successfully, but these errors were encountered: