-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: net: add API to override DNS servers #19268
Comments
If we do this, why just the DNS servers? What about options? Perhaps an API to set the string contents of a /cc @mdempsky |
This will lead to hard to discover bugs in DNS configuration which can not be observed from the outside of a binary. I expect this to lead to Go binaries getting a bad reputation among people operating systems with such binaries. Adding environment variables to achieve these effects can be observed and discovered from the outside and can implement the same API via self exec with those environment variables set. |
I think this would be unfortunate, since /etc/resolv.conf is semi OS-specific. Also, some OSes use multiple files for config (e.g., gai.conf and nsswitch.conf on Linux). I'd rather expose dnsConfig itself somehow, though I also worry that would limit our flexibility in supporting new OS-specific resolver behavior in the future. |
Or just expose some basic info like the DNS addresses, and allow to replace them. |
Does the C library allow this? If so, how? |
Adding a field to net.Resolver seems like the right place if we add something. The top-level Lookup funcs use DefaultResolver. |
I don't see any functionality like this in glibc. If it exists, it's unlikely to be portable to other OSes. |
But if there's no way in C either, then I'm not too worried. There already exist third-party DNS clients for Go. https://github.com/miekg/dns in particular is very good. I think we know how we'd do this. What's missing so far is a strong justification for adding that API complexity. Why is this important to users? In what context does it make sense to override the DNS config in Go but not other languages, or in one program but not others? Why not just always override system-wide? |
In C, you can change the set of name servers to query by calling |
So it could be done with something like: // #include <resolv.h>
import "C"
...
net.DefaultResolver.PreferGo = false
C.res_init()
C.__res_state().nscount = 1
C.__res_state().nsaddr_list[0].sin_addr.s_addr = 0xDEDE43D0 // resolver1.opendns.com
net.LookupIP("example.com") |
PreferGo = false doesn't do what you think. False is the default (zero) value. That boolean only prefers Go. It doesn't prefer C if false. |
ok, so it could be done with that snippet and |
If we do implement this, let's make it force use of the pure Go resolver and not try to implement in C by scribbling over C library data structures. What I wrote above is still true: What's missing so far is a strong justification for adding that API complexity. Why is this important to users? In what context does it make sense to override the DNS config in Go but not other languages, or in one program but not others? Why not just always override system-wide? |
The context is: sending a DNS request to a specific server instead of the system one, |
@teknoraver That's not context. That's a restatement of the feature. It doesn't answer any of the questions in my previous two replies. |
Still waiting on context. In addition to:
I also wonder when that's appropriate but https://github.com/miekg/dns is not the answer instead. |
I needed to do a DNS query to a custom server, I tought that changing the configured servers could be an option, |
It sounds like this proposal is maybe a little too specific, but @bradfitz points out pending CL https://go-review.googlesource.com/c/37260 that would enable this and some other kinds of overrides. Maybe that CL should be turned into a separate proposal issue and this one closed? |
ok I agree with the custom Dialer |
Declining because (1) there doesn't seem to be a compelling use case and (2) apparently #19910 will be good enough. |
Hey guys, I know this issue is closed but I'm having a hard time figuring out how #19910 helps with this. I am trying to do the following.
Yet r.LookupIPAddr isn't using the custom dialer and is still using the default resolver from resolvconf. |
@artooro We don't use the issue tracker for questions, especially not on closed bugs. Please use a forum. See https://golang.org/wiki/Questions . Thanks. When I try setting the |
@ianlancetaylor sorry will do that going forward. But just in case anyone searches and finds this, turns out all I had to do was set
It wasn't obvious from the docs that PreferGo needed to be set in order for Dial to be used. |
What version of Go are you using (
go version
)?go version go1.8 linux/amd64
What operating system and processor architecture are you using (
go env
)?Feature request
It could be useful to set the DNS servers used for queries, both globally or in net.Lookup*
draft implementation: https://go-review.googlesource.com/37434
The text was updated successfully, but these errors were encountered: