在Termux中运行我的Go应用程序时出现DNS查找问题



我正在尝试编写一个Go应用程序,让我生成数字海洋液滴。它在我的台式机和笔记本电脑上工作得很好,但当我试图在Termux的安卓手机上运行它时,我得到了如图所示的问题。我已经在他们的GitHub上提交了一个问题,但我不确定这是否与Termux有关,或者我是否缺少了一些东西。

下面是部分错误:

dial tcp: lookup api.digitalocean.com on [::1]:53: read udp [::1]:39143->[::1]:53: read: connection refused

不确定为什么它试图使用localhost作为dns服务器。日志如下:

Preparing to unpack .../resolv-conf_1.0_aarch64.deb ...
Unpacking resolv-conf (1.0) ...
Selecting previously unselected package dnsutils.
Preparing to unpack .../dnsutils_9.10.4-1_aarch64.deb ...
Unpacking dnsutils (9.10.4-1) ...
Setting up ca-certificates (20160429) ...
Setting up openssl (1.0.2h-1) ...
Setting up resolv-conf (1.0) ...
Setting up dnsutils (9.10.4-1) ...
$ ./fastnet
2016/08/15 02:28:53 Get https://api.digitalocean.com/v2/images?private=true: dial tcp: lookup api.digitalocean.com on [::1]:53: read udp [::1]:39143->[::1]:53: read: connection refused
$ nslookup google.com
Server:         8.8.8.8
Address:        8.8.8.8#53
Non-authoritative answer:
Name:   google.com
Address: 216.58.194.174

创建/etc/resolv.conf并附加nameserver 8.8.8.8那么这个问题就解决了。

根据src/net/dnsclient_unix。如果/etc/resolv.conf不存在,则选择localhost:53作为名称服务器。

因为Android中的Linux不是那么"标准"。/etc/resolv.conf不可用。然后应用程序继续在localhost:53中查找host

我还发现可以使用proot来加载resolv.conf。例子:

pkg install proot resolv-conf
proot -b $PREFIX/etc/resolv.conf:/etc/resolv.conf ./fastnet

我使用termux-chroot解决了我的问题,您可以在这里找到详细信息https://wiki.termux.com/wiki/Differences_from_Linux

您的手机正在尝试连接自己:[::1]:39143->[::1]:53

我猜你的手机可能没有运行本地DNS服务器,所以你得到connection refused错误。

你的nslookup是无关的,因为你直接连接到8.8.8.8。请尝试使用nslookup ::1dig @::1 google.com A

最新更新