Chinaunix首页 | 论坛 | 博客
  • 博客访问: 279081
  • 博文数量: 42
  • 博客积分: 485
  • 博客等级: 下士
  • 技术积分: 482
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-26 19:33
文章分类
文章存档

2017年(1)

2016年(4)

2015年(8)

2014年(3)

2013年(4)

2012年(3)

2011年(19)

我的朋友

分类: Android平台

2015-07-21 11:56:35

android 4.1系统上,通过usb以太网进行上网,发现udhcpc获取到ip和dns,并且ip设置到网络节点成功,dns server也配置到/etc/resolv.conf文件中成功,但总是ping IP正常,而ping domain失败:unkown host.
最后,有同事发现原来android上的dns配置与linux上有所不同,android上还需要通过设置属性net.dns1,net.dns2,setprop后即可正常工作了。。。

附参考:http://blog.163.com/my_ywj/blog/static/1812035592011730104753938/

通过ubuntu等Linux系统都是通过resolve.conf文件进行域名解析的,通过man resolve.conf可以查看到:

 

The  resolver is a set of routines in the C library that provide access to the Internet Domain Name System (DNS).  The  resolver  configuration file  contains  information  that  is read by the resolver routines the first time they are invoked by a process.  The file is designed  to  be human readable and contains a list of keywords with values that provide various types of resolver information. If this file doesn't exist the only name server to be queried  will  be       on  the  local machine; the domain name is determined from the hostname and the domain search path is constructed from the domain name.

 

所以DNS解析是由C库函数进行解析的,在Android中bionic/libc/docs/overview.txt文件中我们也可以看到:

NS resolver:
  Bionic uses a NetBSD-derived resolver library which has been modified in the following ways:
     - don't implement the name-server-switch feature (a.k.a. <nsswitch.h>)
     - read /system/etc/resolv.conf instead of /etc/resolv.conf
     - read the list of servers from system properties. the code looks for 'net.dns1', 'net.dns2', etc.. Each property should contain the IP address of a DNS server.
       these properties are set/modified by other parts of the Android system (e.g. the dhcpd daemon).
       the implementation also supports per-process DNS server list, using the properties 'net.dns1.<pid>', 'net.dns2.<pid>', etc... Where <pid> stands for the numerical ID of the current process.
     - when performing a query, use a properly randomized Query ID (instead of a incremented one), for increased security.
     - when performing a query, bind the local client socket to a random port for increased security.
     - get rid of *many* unfortunate thread-safety issues in the original code
  Bionic does *not* expose implementation details of its DNS resolver; the content of <arpa/nameser.h> is intentionally blank. The resolver implementation might change completely in the future.

所以android关注的是resolv.conf以及net.dns1等属性。

 

通 过adb shell中通过getprop查看属性,确实有net.dns1、net.dns2以及wifi中的net.tiwlan0.dns1以及 net.tiwlan0.dns2,移动网络中的net.rmnet0.dns1以及net.rmnet0.dns2等属性。


阅读(12703) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~