android 5.0路由表,Android路由表设置(route & DNS)

route设置

android4.4只使用了一份路由表,使用busybox route就可以完成路由表的设置,从android5.0之后,考虑要对多网络的支持,采用了多路由表,下面的设置方法只适用于android4.4之前的版本,android5.0之后的版本路由表如何设置留到以后再说明。

1、查看路由表 busybox route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

0.0.0.0 192.168.7.1 0.0.0.0 UG 202 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

192.168.7.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0

2、删除默认路由 busybox route del default

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 202 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

192.168.7.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0

3、添加一条默认路由 busybox route add -net 0.0.0.0 gw 192.168.7.1 netmask 0.0.0.0 dev eth0

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

192.168.7.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0

4、删除一条主机路由 busybox route del -host 192.168.7.1 dev eth0

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

5、添加一条主机路由 busybox route add -host 192.168.7.1 dev eth0

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

192.168.7.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0

6、删除一条网络路由 busybox route del -net 192.168.0.0 netmask 255.255.248.0 dev eth

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

7、添加一条网络路由 busybox route add -net 192.168.0.0 netmask 255.255.248.0 dev eth

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

0.0.0.0 192.168.7.1 0.0.0.0 UG 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 0 0 0 eth0

192.168.0.0 0.0.0.0 255.255.248.0 U 202 0 0 eth0

DNS Server设置

同样以android4.4为例来进行说明,Android系统中,不管是dns server的设置,还是域名解析,都是由netd进程来执行的,netd与dns的相关操作是调用了一个netbsd的库,netd中dns server设置对应于文件ResolverController.cpp,域名解析对应于文件DnsProxyListener.cpp。

原生的android系统只提供了设置系统dns server的接口,而没有提供查看系统dns server的接口,需要自己添加代码来实现。

通过ndc配合netd可以对android dns进行设置和查看。

1、设置dns interface & server

ndc resolver setdefaultif eth0

ndc resolver setifdns eth0 “” 192.168.7.2

2、查看dns interface

ndc resolver getdefaultif

226 0 DNS default interface is eth0

3、查看dns server

ndc resolver getdefaultServer 1

226 0 DNS default server[1] is 192.168.7.2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值