android是如何做DNS解析的

來源:互聯網
上載者:User

通過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等屬性。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.