9

I am trying to write a Go App that lets me spawn Digital Ocean droplets. It works fine on my desktop and laptop, but when I try to run it on my Android phone in Termux I get the issue shown in the image. I already filed an issue on their GitHub, but I am not sure if this is related to Termux or if I am missing something.

Here is part of the error:

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

Not sure why it is trying to use localhost as a dns server. Here is the log:

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
林果皞
  • 7,539
  • 3
  • 55
  • 70
Cucumber
  • 93
  • 1
  • 4
  • 2
    Hi Cucumber, and welcome to Stack Overflow. About the image you have linked - it would be better if you copy the console log and error message, in full, into your question. That way anybody can get the complete question information in one place, without having to refer to any other site. – Vince Bowdren Aug 15 '16 at 16:36

4 Answers4

5

Just create /etc/resolv.conf and append nameserver 8.8.8.8 then this problem will be resolved.

According to src/net/dnsclient_unix.go, if /etc/resolv.conf is absent, localhost:53 is chosen as a name server.

Since the Linux in Android is not so "standard". /etc/resolv.conf is not available. The app then just keep looking up host in localhost:53.

woohaha
  • 144
  • 2
  • 5
  • Thanks a lot! I believe this got fixed in the recent termux. – Cucumber Mar 17 '18 at 08:22
  • 2
    @Cucumber I don't think this got fixed at all (e.g. [this](https://github.com/termux/termux-packages/commit/70dae767351e8909a5ac7d1eba064db294cd5b8f)). According to [termux/termux-app#210](https://github.com/termux/termux-app/issues/210) you need to compile with [termux-golang package](https://github.com/termux/termux-packages/tree/master/packages/golang) so you get linked to termux libc. I assume that the libc will detect and use `$TERMUX_PREFIX/etc/resolv.conf`. At least thats the [termux way](https://github.com/termux/termux-packages/blob/master/packages/resolv-conf/build.sh). – Vlastimil Ovčáčík Apr 21 '18 at 15:43
  • You might need root and remount `/system` temporarily if it is [read-only](https://stackoverflow.com/a/8534641/2587343). – Vlastimil Ovčáčík Apr 21 '18 at 15:45
  • 1
    What other workarounds are possible on a *non rooted* phone? Is it to change the default DNS server at build time? – Absurdev Nov 05 '19 at 17:48
2

I also found that proot could be used in order to load the resolv.conf. Example:

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

Source

Hirbod Behnam
  • 577
  • 2
  • 7
  • 26
2

I solved my problem using termux-chroot, you can find the detail here https://wiki.termux.com/wiki/Differences_from_Linux

Adzimzf
  • 181
  • 2
  • 11
1

Your phone is trying to connect to itself: [::1]:39143->[::1]:53

My guess is your phone is probably not running a local DNS server and so you get the connection refused error.

Your nslookup is irrelevant because you connected directly to 8.8.8.8. Instead, try nslookup ::1 or dig @::1 google.com A