ping DNS issue! ping returns "unknown host www.yahoo.com" but ping to IP works fine

2,855 views
Skip to first unread message

jolly1312

unread,
Aug 12, 2009, 2:58:11 PM8/12/09
to android-porting
I am trying to get the ping working in Android running on ARM.

Ping to IP addresses works fine but when I ping to name I get

"ping: unknown host www.yahoo.com"

I have already setup the default gateway:
route add default gw 192.168.0.17

Also /etc/resolv.conf is also there:
echo nameserver 4.2.2.2 > /etc/resolv.conf

And ping to nameserver works fine!

Also I have /etc/nsswitch.conf as:
echo "hosts: files dns" > /etc/nsswitch.conf

If I add entries in /etc/hosts then the ping with name works fine.

Has anyone seen this problem before?

jolly1312

unread,
Aug 12, 2009, 3:13:07 PM8/12/09
to android-porting
Following is the strace output:


#strace ping -c 1 www.yahoo.com
execve("/system/bin/ping", ["ping", "-c", "1", "www.yahoo.com"], [/*
10 vars */]) = 0
getpid() = 811
syscall_983045(0xb00189fc, 0x85b4, 0xb0010448, 0x10, 0x4, 0xbe85cd64,
0x6fb0, 0xf0005, 0, 0, 0, 0, 0, 0xbe85cd10, 0xb00016d1, 0xb00021fc,
0x80000010, 0xb00189fc, 0xb9f1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
= 0
gettid() = 811
sigaction(SIGILL, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGABRT, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGBUS, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGFPE, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGSEGV, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGSTKFLT, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
sigaction(SIGPIPE, {0xb0001c65, [], SA_RESTART}, {SIG_DFL}, 0) = 0
getuid32() = 0
geteuid32() = 0
getgid32() = 0
getegid32() = 0
stat64("/system/lib/libc.so", {st_mode=S_IFREG|0644,
st_size=243980, ...}) = 0
open("/system/lib/libc.so", O_RDONLY|O_LARGEFILE) = 3
lseek(3, 0, SEEK_SET) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0`¦\0\000"...,
4096) = 4096
lseek(3, -8, SEEK_END) = 243972
read(3, "\0\0¦PRE ", 8) = 8
mmap2(0xafe00000, 290816, PROT_READ|PROT_EXEC, MAP_PRIVATE|
MAP_ANONYMOUS, -1, 0) = 0xafe00000
mmap2(0xafe00000, 229744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
3, 0) = 0xafe00000
mprotect(0xafe00000, 233472, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0xafe39000, 8536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
3, 0x39) = 0xafe39000
mmap2(0xafe3c000, 41956, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|
MAP_ANONYMOUS, -1, 0) = 0xafe3c000
close(3) = 0
mprotect(0xafe00000, 233472, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
getgid32() = 0
getegid32() = 0
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3
read(3, "\226\21\211!", 4) = 4
close(3) = 0
stat64("/system/lib/libstdc++.so", {st_mode=S_IFREG|0644,
st_size=5124, ...}) = 0
open("/system/lib/libstdc++.so", O_RDONLY|O_LARGEFILE) = 3
lseek(3, 0, SEEK_SET) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\234\10\0"...,
4096) = 4096
lseek(3, -8, SEEK_END) = 5116
read(3, "\0\0?PRE ", 8) = 8
mmap2(0xafd00000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|
MAP_ANONYMOUS, -1, 0) = 0xafd00000
mmap2(0xafd00000, 2860, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3,
0) = 0xafd00000
mprotect(0xafd00000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0xafd01000, 232, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0x1) = 0xafd01000
close(3) = 0
mprotect(0xafd00000, 4096, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
getgid32() = 0
getegid32() = 0
stat64("/system/lib/libm.so", {st_mode=S_IFREG|0644,
st_size=136148, ...}) = 0
open("/system/lib/libm.so", O_RDONLY|O_LARGEFILE) = 3
lseek(3, 0, SEEK_SET) = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0004!\0\000"...,
4096) = 4096
lseek(3, -8, SEEK_END) = 136140
read(3, "\0\0¦PRE ", 8) = 8
mmap2(0xafc00000, 139264, PROT_READ|PROT_EXEC, MAP_PRIVATE|
MAP_ANONYMOUS, -1, 0) = 0xafc00000
mmap2(0xafc00000, 132092, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,
3, 0) = 0xafc00000
mprotect(0xafc00000, 135168, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0xafc21000, 240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3,
0x21) = 0xafc21000
close(3) = 0
mprotect(0xafc00000, 135168, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
getgid32() = 0
getegid32() = 0
mprotect(0x8000, 24576, PROT_READ|PROT_EXEC) = 0
getuid32() = 0
geteuid32() = 0
getgid32() = 0
getegid32() = 0
gettid() = 811
syscall_983045(0xbe85cbdc, 0, 0x40, 0, 0xbe83d000, 0xbe85cd18,
0xbe85ccdc, 0xf0005, 0, 0, 0, 0, 0, 0xbe85cbc0, 0xafe1fcef,
0xafe0d2cc, 0x60000010, 0xbe85cbdc, 0xb9f1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0) = 0
mmap2(NULL, 32768, PROT_READ, MAP_SHARED, 9, 0) = 0x40000000
mq_notify(0x2, 0x3) = 3
getuid32() = 0
setuid32(0) = 0
brk(0) = 0x22000
brk(0x22000) = 0x22000
brk(0x27000) = 0x27000
getpid() = 811
gettimeofday({1258506883, 453125}, NULL) = 0
getpid() = 811
uname({sys="Linux", node="localhost", ...}) = 0
getpid() = 811
gettimeofday({1258506883, 460937}, NULL) = 0
getpid() = 811
uname({sys="Linux", node="localhost", ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x40008000
mprotect(0x40008000, 4096, PROT_READ) = 0
open("/system/etc/hosts", O_RDONLY|O_LARGEFILE) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
read(4, "127.0.0.1\t\t localhost\n74.125."..., 1024) = 54
read(4, "", 1024) = 0
close(4) = 0
mmap2(NULL, 69632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x40009000
gettimeofday({1258506883, 468750}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 468750}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 468750}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
gettimeofday({1258506883, 476562}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 476562}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 476562}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
munmap(0x40009000, 69632) = 0
open("/system/etc/hosts", O_RDONLY|O_LARGEFILE) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
brk(0x28000) = 0x28000
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
read(4, "127.0.0.1\t\t localhost\n74.125."..., 1024) = 54
read(4, "", 1024) = 0
close(4) = 0
mmap2(NULL, 69632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x40009000
gettimeofday({1258506883, 820312}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 820312}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 820312}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
gettimeofday({1258506883, 828125}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 828125}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 828125}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
munmap(0x40009000, 69632) = 0
open("/system/etc/hosts", O_RDONLY|O_LARGEFILE) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
read(4, "127.0.0.1\t\t localhost\n74.125."..., 1024) = 54
read(4, "", 1024) = 0
close(4) = 0
mmap2(NULL, 69632, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x40009000
gettimeofday({1258506883, 835937}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 835937}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 843750}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
gettimeofday({1258506883, 843750}, NULL) = 0
getpid() = 811
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506883, 851562}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
mq_notify(0x2, 0x2) = 4
gettimeofday({1258506884, 179687}, NULL) = 0
getpid() = 811
mq_getsetattr(0x4, 0xbe85b510, 0x10) = 0
sys_kexec_load(0x4, 0x2201c, 0x10, 0x21891196, 0x221e4) = 0
SYS_290(0x4, 0xbe85bc84, 0x1f, 0, 0) = 31
timer_delete(0) = 0
select(5, [4], NULL, NULL, {5, 0}) = 1 (in [4], left {5, 0})
SYS_292(0x4, 0x40009008, 0x10000, 0, 0xbe85b61c) = -1 ECONNREFUSED
(Connection refused)
close(4) = 0
munmap(0x40009000, 69632) = 0
write(2, "ping: unknown host www.yahoo.com"..., 33ping: unknown host
www.yahoo.com
) = 33
mprotect(0x40008000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40008000, 4096, PROT_READ) = 0
munmap(0x40008000, 4096) = 0
io_submit(2, -1343986744, {...} <unfinished ... exit status 2>

Csillag Tamas

unread,
Aug 12, 2009, 5:26:07 PM8/12/09
to android...@googlegroups.com
On Wed, Aug 12, 2009 at 11:58:11AM -0700, jolly1312 wrote:
> I am trying to get the ping working in Android running on ARM.
>
> Ping to IP addresses works fine but when I ping to name I get
>
> "ping: unknown host www.yahoo.com"
...

> Also /etc/resolv.conf is also there:
> echo nameserver 4.2.2.2 > /etc/resolv.conf

I think the thing is that android userland tools (bionic libc) does
not use resolv.conf nor nss. You should use busybox for this purpose.

Regards,
cstamas
--
CSILLAG Tamas (cstamas) - http://digitus.itk.ppke.hu/~cstamas

Nikhil Gautam

unread,
Aug 12, 2009, 6:09:00 PM8/12/09
to android...@googlegroups.com
Thanks Csillag,

I did tried busybox and it produces the similar error. The only difference is with busybox, I can't even ping "localhost" which is defined in /etc/hosts. Ping to IP address works fine.
Note: I am building busybox statically linked.

Do you know how does android applications resolve names or how do I get the android ping to work with name?

Thanks.

Jolly

2009/8/12 Csillag Tamas <cst...@digitus.itk.ppke.hu>

hailong zeng

unread,
Aug 12, 2009, 10:47:39 PM8/12/09
to android-porting
hi!
dns resolving for android system does not use /etc/resolv.conf.it
do the task internal.
you might set it using the following command:"setprop net.dns1
xxx.xxx.xxx.xxx".

Jerome Duval

unread,
Aug 13, 2009, 1:05:36 AM8/13/09
to android...@googlegroups.com
Maybe I'm missing something, but I don't see you describing your DNS client anywhere. Does the bionic libc do that?

Nikhil Gautam

unread,
Aug 13, 2009, 1:10:40 AM8/13/09
to android...@googlegroups.com
I think it's handled by libc. From busybox, I see the getaddrinfo() call which returns an error. I think internally the gethostbyname() function inside libc fails.

Nikhil Gautam

unread,
Aug 13, 2009, 1:14:19 AM8/13/09
to android...@googlegroups.com
Thanks, I was doing "setprop net.usb0.dns1 xxx.xxx.xxx.xxx" and it didn't work.

I'll try removing usb0 and see if it works!

2009/8/12 hailong zeng <hailon...@gmail.com>

jolly1312

unread,
Aug 13, 2009, 12:17:27 PM8/13/09
to android-porting
Thanks everyone.

Hailong, your command worked like a charm. DNS stuff is working now on
Android.

Why statically linked busybox doesn't work is separate issue which
I'll tackle some other day.

Thanks again.

On Aug 12, 10:14 pm, Nikhil Gautam <jolly1...@gmail.com> wrote:
> Thanks, I was doing "setprop net.usb0.dns1 xxx.xxx.xxx.xxx" and it didn't
> work.
> I'll try removing usb0 and see if it works!
>
> 2009/8/12 hailong zeng <hailong.z...@gmail.com>

jolly1312

unread,
Aug 13, 2009, 12:19:09 PM8/13/09
to android-porting
Thanks everyone.

Hailong, your command worked like a charm. DNS stuff is working now on
Android.

Why statically linked busybox doesn't work is separate issue which
I'll tackle some other day.

Thanks again.

On Aug 12, 10:14 pm, Nikhil Gautam <jolly1...@gmail.com> wrote:
> Thanks, I was doing "setprop net.usb0.dns1 xxx.xxx.xxx.xxx" and it didn't
> work.
> I'll try removing usb0 and see if it works!
>
> 2009/8/12 hailong zeng <hailong.z...@gmail.com>

David Turner

unread,
Aug 14, 2009, 1:01:47 AM8/14/09
to android...@googlegroups.com
The Android C library contains a DNS resolver that doesn't use /etc/resolv.conf or /etc/nsswitch.conf
Instead, to it uses a list of system properties instead:

net.dns1 -> IP address of first DNS server
net.dns2 -> IP address of second DNS server
...

Additionally, the Donut platform (not Cupcake) also supports

net.dns.search -> space separated domain search suffixes (used e.g. by VPN)

Sunny Liu

unread,
Sep 15, 2009, 3:45:35 AM9/15/09
to android...@googlegroups.com
Hi!

I found one problem in resolv module there :
setprop net.dns1 168.95.1.1
setprop net.dns2 168.95.192.1

But ping -c 10 www.google.com failed!

From Win XP nsllookup to check : dns is 168.95.1.1
C:\Documents and Settings\sunnyliu>nslookup www.google.com
Server:  dns.hinet.net
Address:  168.95.1.1

Non-authoritative answer:
Name:    www.l.google.com
Addresses:  72.14.203.105, 72.14.203.103, 72.14.203.104, 72.14.203.99
          72.14.203.147, 72.14.203.106
Aliases:  www.google.com

How do we debug this problem?

Thank you at the first!


Sunny Liu


2009/8/14 David Turner <di...@android.com>
Reply all
Reply to author
Forward
0 new messages