Android 8.0网络DNS

本文详细探讨了Android系统中DNS解析的实现机制,包括Linux DNS规范、netd DNS的工作流程、DNS解析函数、网络基础库的DNS处理方式、DHCP中的DNS服务器地址获取以及netId的概念和使用。同时,介绍了如何利用ndc命令管理和调试netd DNS。

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值