RK3288-7.1下实现4G路由功能,即:4G网络通过RJ45共享给其他设备,比如PC
需求:产品有WIFI,4G,以太网接口,工作在室外,想把4G信号共享到RJ45输出,RJ45连接到交换机,
交换机再连接其他设备,组成局域网功能。
思路:先实现4G和以太网共存,再把4G信号通过iptables实现路由转发,先再adb下用命令实现,然后在 java层封装接口
1.先打上RK双以太网共存补丁《Android 支持双以太网卡补丁20180108》,
2.基本信息获取,
A:ifconfig
AT5:/ # ifconfig
ifconfig
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.171.2.114 P-t-P:10.64.64.64 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:170 errors:0 dropped:0 overruns:0 frame:0
TX packets:748 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:45978 TX bytes:88922
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope: Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 TX bytes:0
AT5:/ #
从中可得,4G获取到的IP是:10.171.2.114
B:获取4G DNS
AT5:/ # getprop | grep -rn dns
getprop | grep -rn dns
(standard input):74:[net.change]: [net.dns2]
(standard input):75:[net.dns1]: [120.196.165.7]
(standard input):76:[net.dns2]: [221.179.38.7]
(standard input):78:[net.ppp0.dns1]: [120.196.165.7]
(standard input):79:[net.ppp0.dns2]: [221.179.38.7]
AT5:/ #
可知4G获取到的DNS是120.196.165.7
3.adb指令实现
#!/system/bin/sh
ip rule add from all lookup main pref 9999(更改优先级为最高)
ifconfig eth0 down
ifconfig eth0 up
busybox ifconfig eth0 192.168.43.1 (设置eth0)
ndc netd 5003 tether start 192.168.43.2 192.168.43.254(设置路由地址范围)
ndc netd 7 nat enable eth0 ppp0 2 10.6.194.114/24(设置转发地址,24位mask地址)
echo 1 >/proc/sys/net/ipv4/ip_forward(使能转发)
iptables -t nat -I PREROUTING -i eth0 -p udp --dport 53 -j DNAT --to-destination 120.196.165.7(ppp0 DNS)
4.Android层封装参考https://blog.csdn.net/zhoumushui/article/details/102892554
有技术问题:欢迎咨询QQ: 1617890720(如果你把我当成免费的答案提取机,就免加了)