Skip to content
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

when /etc/nsswitch.conf doesn't exist , Go's DNS work like an unexpect way #40920

Closed
MemorySpring opened this issue Aug 20, 2020 · 2 comments
Closed

Comments

@MemorySpring
Copy link

@MemorySpring MemorySpring commented Aug 20, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.8 linux/amd64
but the problem exist in both 1.12 1.13 1.14 ...

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build381088182=/tmp/go-build -gno-record-gcc-switches"

What did you do?

in remote DNS server
a.test.com reslove as 10.10.10.10
in /etc/hosts i hava a record
9.9.9.9 a.test.com

golang app will reslove a.test.com as 10.10.10.10
however , ping curl php app java app and so on will resolve a.test.com as 9.9.9.9

What did you expect to see?

when /etc/nsswitch.conf doesn't exist ,Go's DNS use file first
in this , golang app should resolve a.test.com as 9.9.9.9

What did you see instead?

golang app will reslove a.test.com as 10.10.10.10

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 20, 2020

Change https://golang.org/cl/249446 mentions this issue: net: change hostLookupOrder when /etc/nsswitch.conf not exists

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 20, 2020

The GNU/Linux man nsswitch.conf is clear, as is the implementation: if there is no hosts line in /etc/nsswitch.conf, the default is "dns [!UNAVAIL=return] files". And that is what the net package implements.

The behavior you are seeing is not due to the net package handling of /etc/nsswitch.conf. It's due to how the C getaddrinfo function works. The C function calls inet_aton and inet_pton before checking either DNS or /etc/hosts. In other words, the C function is not doing a DNS lookup; it's first checking whether it has an IP address. If that's the behavior you want, call net.ParseIP.

I'm going to close this issue because it is not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.