Android shell 命令設置(獲取)IP地址、網關、dns

轉自 http://www.biemmeitalia.net/blog/android-network-configuration/android

經過shell命令設置(獲取)IP、網關、dns信息,須要獲取root權限shell

查看全部網絡信息網絡

C:\>adb shell
root@android:/ # netcfg
netcfg
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
gre0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
eth0     UP                               192.168.0.180/24  0x00001043 00:00:00:
ec:0a:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:
00:00:00
tunl0    DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00

查看eth0.net

root@android:/ # ifconfig eth0
ifconfig eth0
eth0: ip 192.168.0.180 mask 255.255.255.0 flags [up broadcast running multicast]

查看dnscode

root@android:/ # getprop net.eth0.dns1
getprop net.eth0.dns1
8.8.8.8

root@android:/ # getprop net.eth0.dns2
getprop net.eth0.dns2
8.8.4.4

設置ipserver

root@android:/ # ifconfig eth0 192.168.0.173 netmask 255.255.255.0
ifconfig eth0 192.168.0.173 netmask 255.255.255.0

root@android:/ # ifconfig eth0
ifconfig eth0
eth0: ip 192.168.0.173 mask 255.255.255.0 flags [up broadcast running multicast]

設置網關Gatewayblog

root@android:/ # route add default gw 192.168.0.1 dev eth0
route add default gw 192.168.0.1 dev eth0

添加dnsdns

root@android:/ # setprop net.eth0.dns1 8.8.8.8
setprop net.eth0.dns1 8.8.8.8

root@android:/ # setprop net.eth0.dns2 8.8.4.4
setprop net.eth0.dns2 8.8.4.4

查看eth配置信息ip

root@android:/ # getprop | grep eth0
getprop | grep eth0
[dhcp.eth0.dns1]: [192.168.0.1]
[dhcp.eth0.dns2]: []
[dhcp.eth0.dns3]: []
[dhcp.eth0.dns4]: []
[dhcp.eth0.gateway]: [192.168.0.1]
[dhcp.eth0.ipaddress]: [192.168.0.180]
[dhcp.eth0.leasetime]: [3600]
[dhcp.eth0.mask]: [255.255.255.0]
[dhcp.eth0.pid]: [13800]
[dhcp.eth0.reason]: [PREINIT]
[dhcp.eth0.result]: [failed]
[dhcp.eth0.server]: [192.168.0.1]
[dhcp.eth0.vendorInfo]: []
[net.change]: [net.eth0.dns2]
[net.eth0.dns1]: [8.8.8.8]
[net.eth0.dns2]: [8.8.4.4]
相關文章
相關標籤/搜索