Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DNS lookup issue when running my Go app in Termux

Tags:

android

go

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
like image 499
Cucumber Avatar asked Aug 15 '16 16:08

Cucumber


Video Answer


2 Answers

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.

like image 72
woohaha Avatar answered Oct 26 '22 23:10

woohaha


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

like image 23
Hirbod Behnam Avatar answered Oct 27 '22 01:10

Hirbod Behnam