英文:
How do i make go dns lookup force usage of nscd if available?
问题
有没有办法强制一个Go二进制文件在同一台主机上执行DNS查找并从nscd缓存中获取响应,如果可用的话?
我猜如果我使用自定义解析器,可以强制执行,但我想避免这样做。想知道netdns=cgo是否会在这里有所帮助?
英文:
Is there any way i can force a go binary to perform dns lookup's and get response from the nscd cache on the same host if it is available?
I assume it can be forced if i use a custom resolver, but i'd like to avoid that. Wondering if netdns=cgo would help here?
答案1
得分: 1
是的,但这取决于你的环境。
你可以通过在终端中输入以下命令来使用cgo
解析器:
export GODEBUG=netdns=cgo
然后你的Go应用程序将使用cgo解析器。
如果你的操作系统是UNIX,cgo解析器将使用getaddrinfo
来解析域名。
而且,如果nscd
服务正在运行,getaddrinfo
将使用nscd
。
参考资料:
[1] https://pkg.go.dev/net#hdr-Name_Resolution
[2] https://stackoverflow.com/questions/70468536/is-golang-caching-dns
[3] https://revs.runtime-revolution.com/golang-dns-resolving-a56ed59981fe
英文:
Yes but it depends on your environment.
You can use cgo
resolver by typing to terminal
export GODEBUG=netdns=cgo
Then your go application will use cgo resolver.
cgo resolver use getaddrinfo
when resolving domain names if your OS is UNIX.
And getaddrinfo
will use nscd
if nscd
service is running.
ref.
[1] https://pkg.go.dev/net#hdr-Name_Resolution
[2] https://stackoverflow.com/questions/70468536/is-golang-caching-dns
[3] https://revs.runtime-revolution.com/golang-dns-resolving-a56ed59981fe
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论