Why golang Lookup*** function can't provide a server parameter?

后端 未结 5 1268
心在旅途
心在旅途 2020-12-14 18:11

For nslookup command, it has nslookup somewhere.com some.dns.server.

However, it seems that golang dnsclient only load config from /

5条回答
  •  天命终不由人
    2020-12-14 18:59

    Since Go 1.9 this is possible by overriding the Dial function on a Resolver. For example, to ignore the request for the local resolver over UDP and connect to 9.9.9.9 via TCP we might do something like this:

    r := &net.Resolver{
        Dial: func(ctx context.Context, _, _ string) (net.Conn, error) {
            return net.Dial("tcp", "9.9.9.9")
        },
    }
    addrs, err := r.LookupIPAddr(context.TODO(), "example.net")
    

提交回复
热议问题