-1

How do I change the IP address of the DNS server?

In situation, I set Google DNS server in Windows Network Settins.

And I use LookupTXT function in Golang for getting DNS txt request. But LookupTXT parameter is just the query string.

Any help or pointers would be highly appreciated. Thanks!

Azeem
  • 11,148
  • 4
  • 27
  • 40
user2491067
  • 21
  • 1
  • 6
  • "On Windows, the resolver always uses C library functions, such as GetAddrInfo and DnsQuery." - [doc](https://golang.org/pkg/net/#hdr-Name_Resolution) – Michael Hampton Apr 17 '18 at 03:53

1 Answers1

0

This is not straigtforward to do using golang at this point. You can however use a third party DNS package that allows configuring the resolver. First install the package:

go get github.com/bogdanovich/dns_resolver

Here is an example using it and the google resolvers 8.8.8.8 and 8.8.4.4:

package main

import (
    "log"
    "github.com/bogdanovich/dns_resolver"
)

func main() {
    resolver := dns_resolver.New([]string{"8.8.8.8", "8.8.4.4"})

    // In case of i/o timeout
    resolver.RetryTimes = 5

    ip, err := resolver.LookupHost("google.com")
    if err != nil {
        log.Fatal(err.Error())
    }
    log.Println(ip)
    // Output [216.58.192.46]
}

Source

There is an open issue in golang here, so hopefully it becomes easier to do it with the builtin net package: https://github.com/golang/go/issues/12503. It could just be a documentation problem, as it is possible now, I just can't find an example.

EDIT: actually that package only supports lookupHost: https://github.com/bogdanovich/dns_resolver/blob/master/dns_resolver.go#L51-L79

So a PR would be required to add a TXT resolver.

2nd Edit: I made a PR with txt lookup here. That project hasn't been touched in years though so it may never get accepted.

rofls
  • 4,993
  • 3
  • 27
  • 37