Android 9.0雙網卡轉發到wlan0上網並通過busybox 獲取gateway

  • busybox traceroute -q 1 -m 1 1.0.0.0 | sed -n 2p | cut -b 5- | cut -d ’ ’ -f 1 | awk ‘$1=$1’
  • tb8788p1_64_bsp:/ # busybox traceroute -w 1 -q 1 -m 1 1.0.0.0 | sed -n 2p | cut -b 2-
    1 192.168.50.1 (192.168.50.1) 3.360 ms
1|tb8788p1_64_bsp:/ # busybox traceroute -q 1 -m 1 1.0.0.0 | sed -n 2p | cut -b 5- | cut -d ' ' -f 1 | awk '$1=$1'
192.168.50.1

雙網卡轉發:把eth0上的某個IP請求上網轉發wlan0上.

  • 先清空iptabes;
iptables -F #注意該命令並不會清空其他表,例如NAT表等
  • 在NAT表中添加轉發
iptables -t nat -A POSTROUTING -s 192.168.50.100 -o wlan0 -j MASQUERADE #將192.168.50.100的請求全部轉發到wifi上.

在9以下此時是可以上網的,但是在9上不行,通過調試發現少了gateway在route表裏面,所以用Busybox route -n查看然後添加默認網關

busybox route add default gw 192.168.10.1(your wifi gateway)
tbadfadf_dsfs:/ # iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 303 packets, 51475 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  303 51475 oem_nat_pre  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain INPUT (policy ACCEPT 286 packets, 46179 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 2002 packets, 121K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 2002 packets, 121K bytes)
 pkts bytes target     prot opt in     out     source               destination         
 2002  121K tetherctrl_nat_POSTROUTING  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 MASQUERADE  all  --  *      wlan0   192.168.50.100       0.0.0.0/0           

Chain oem_nat_pre (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain tetherctrl_nat_POSTROUTING (1 references)
 pkts bytes target     prot opt in     out     source               destination 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章