android网卡调试命令

android开发中,经常遇到的调试工具汇总如下:

静态IP设置:
1. 设置指定网卡的IP地址和子网掩码:
busybox ifconfig ethx IP地址 netmask 子网掩码

2. 设置指定网卡的网关:
route add default gw 192.168.1.1 dev ethx

3. 设置指定网卡DNS
setprop net.eth1.dns1 192.168.1.1
上面的方法会导致问题:网卡ping外网域名不通,ping网关或某IP地址正常。
解决:设置全局dns,方法如下:
setprop net.dns1 192.168.1.1

查看DNS:
getprop |grep dns
示例:
root@sabresd_6dq:/ # getprop |grep dns
[dhcp.eth0.dns1]: [114.114.114.114]
[dhcp.eth0.dns2]: [1.2.4.8]
[dhcp.eth0.dns3]: []

上面[net.dns1]不是某个网卡的dns,而是全局dns


DHCP设置:
netcfg ethx dhcp   //通过dhcp 自动获取ip、网关、掩码、dns等
netcfg(网络配置命令):查看IP地址、MAC地址、打开或关闭等


设置网卡MAC地址:
busybox ifconfig ethx down
busybox ifconfig ethx hw ether 1234567890ab
busybox ifconfig ehtx up
注意:该方法缺点:MAC地址无法保存,重启后,设置的MAC地址丢失。

关闭/开启网卡:
关闭:busybox ifconfig eth0 down
打开: busybox ifconfig eth0 up

指定特定网卡ping网络:
ping -I eth0 192.168.1.1


路由跟踪:

windows: tracert IP地址

android:busybox traceroute 114.114.114.114(IP地址)


另外,还可以利用 ethtool 工具进行调试,例如:

设置网卡速率(切换网卡速率):
示例:设置eth0速率为100M,网卡自动协商关闭,全双工
./ethtool -s eth0 speed 100 autoneg off duplex full 


ethtool 功能很强大,此处不一一阐述。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值