猿问

通过 Cisco IPSec 连接时,应用程序无法解析内部 DNS 条目

我使用 Cisco IPsec 连接到我的工作场所 VPN。我使用 OS X 的本机 Cisco IPSec 客户端进行连接。我们有一个内部 DNS 服务器,用于保存内部站点的记录,例如scotty.infinidat.com. 使用 curl 联系内部站点按预期工作。使用以下 Python 代码也可以:


import requests


resp = requests.get("http://www.google.com")

resp.raise_for_status()


resp = requests.get("http://scotty.infinidat.com")

resp.raise_for_status()

但是,尝试在 Go 中实现等价物失败:


包主


import (

    "fmt"

    "net/http"

)


func main() {

    _, err := http.Get("http://google.com/") // This works

    if err != nil {

        panic(fmt.Sprintf("Error contacting Google: %s", err))

    }


    _, err = http.Get("http://scotty.infinidat.com/") // This doesn't

    if err != nil {

        panic(fmt.Sprintf("Error contacting an internal site: %s", err))

    }

}

在连接到 VPN 时运行上述程序会产生以下输出:


panic: Error contacting internal site: Get http://scotty.infinidat.com/: dial tcp: lookup scotty.infinidat.com on 10.135.1.1:53: no such host


goroutine 1 [running]:

panic(0x290ca0, 0xc82010a490)

        /usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:481 +0x3e6

main.main()

        /Users/roeyd/src/go/src/webtest/main.go:16 +0x2af

其中 10.135.1.1 是我本地网络的 DNS 服务器。据我了解,纯 Go DNS 解析器在 OS X 上不可用。通过设置强制 Go 使用 cgo DNS 解析器GODEBUG=netdns=cgo没有任何区别。


SMILET
浏览 375回答 2
2回答

森林海

可能您已经这样做了,但是从我这边执行时dig scotty.infinidat.com我没有记录(与您的结果匹配):$ dig scotty.infinidat.com; <<>> DiG 9.8.3-P1 <<>> scotty.infinidat.com;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 53313;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0;; QUESTION SECTION:;scotty.infinidat.com.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN&nbsp; &nbsp; &nbsp; A;; AUTHORITY SECTION:infinidat.com.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 155&nbsp; &nbsp; &nbsp;IN&nbsp; &nbsp; &nbsp; SOA&nbsp; &nbsp; &nbsp;ns1.dnsimple.com. admin.dnsimple.com. 1438782431 86400 7200 604800 300;; Query time: 234 msec;; SERVER: 10.132.0.1#53(10.132.0.1);; WHEN: Sun Jul 30 21:37:14 2017;; MSG SIZE&nbsp; rcvd: 93因此,如果 forwww.google.com工作正常,那么更改可能与您的 DNS/ZONE 更相关。

大话西游666

或许你可以先用一个完整的DNS库来解析IP:&nbsp;package main&nbsp;import (&nbsp; &nbsp; "log"&nbsp; &nbsp; "github.com/miekg/dns"&nbsp;)&nbsp;func main() {&nbsp; &nbsp; c := dns.Client{}&nbsp; &nbsp; m := dns.Msg{}&nbsp; &nbsp; m.SetQuestion("scotty.infinidat.com.", dns.TypeA)&nbsp; &nbsp; r, t, err := c.Exchange(&m, "10.135.1.1:53")&nbsp; &nbsp; if err != nil {&nbsp; &nbsp; &nbsp; &nbsp; log.Fatal(err)&nbsp; &nbsp; }&nbsp; &nbsp; log.Printf("Took %v", t)&nbsp; &nbsp; for _, ans := range r.Answer {&nbsp; &nbsp; &nbsp; &nbsp; Arecord := ans.(*dns.A)&nbsp; &nbsp; &nbsp; &nbsp; log.Printf("%s", Arecord.A)&nbsp; &nbsp; }&nbsp;}
随时随地看视频慕课网APP

相关分类

Go
我要回答