1 Linux DNS规范
Linux上并没有一个单独的方法可以完成DNS查询工作;没有一个有这样的明确接口的核心系统调用system call。不过,glibc (nss)的getaddrinfo (3), gethostbyname (3)等相关API (RFC3493)提供了DNS查询功能。
1)不支持nscd(name service cache daemon)服务,那么这2个函数接口通过文件/etc/resolv.conf获取DNS服务器的IP地址,然后通过socket通信发送请求到该DNS IP地址去获取待查询域名的IP地址。
2)支持nscd服务(or dnsmasq),这2个函数接口发送请求给nscd,nscd再返回响应给请求者。
3)ping uses glibc gethostbyname()。
2 Android netd DNS
2.1 Android 4.3 DNS
Android 4.3 incorporated a somewhat confusing series of commits under the heading of "dns cache per interface," which effectively causes all Bionic DNS requests to be proxied through netd.
ANDROID_DNS_MODE=local
dumpsys connectivity
dumpsys netd
ndc tether dns set
ndc tether dns list
iptables -t nat -I OUTPUT -p udp \
--dport 53 -j DNAT \
--to-destination 192.168.1.5:53
iptables -t nat -I OUTPUT -p tcp \
--dport 53 -j DNAT \
--to-destination 192.168.1.5:53
This works by intercepting the DNS request
Android 8.0网络DNS
最新推荐文章于 2026-03-04 02:47:56 发布
本文详细探讨了Android系统中DNS解析的实现机制,包括Linux DNS规范、netd DNS的工作流程、DNS解析函数、网络基础库的DNS处理方式、DHCP中的DNS服务器地址获取以及netId的概念和使用。同时,介绍了如何利用ndc命令管理和调试netd DNS。


879

被折叠的 条评论
为什么被折叠?



