當前位置:編程學習大全網 - 網站源碼 - Android5.1 NAT功能的iptables規則

Android5.1 NAT功能的iptables規則

在Android4.2、4.4、5.1上面,我們參照 《Linux下雙網卡NAT組網》 壹文是可以驗證成功的。在Android5.1上面,我們參照了系統裏的WiFi熱點、USB Tether、Bluetooth Tether功能,發現有另壹組命令也可實現:

echo 0 > /proc/sys/net/ipv4/ip_forward

/system/bin/iptables -t nat -A natctrl_nat_POSTROUTING -o eth0 -j MASQUERADE

/system/bin/iptables -A natctrl_FORWARD -i eth0 -o ap0 -m state --state ESTABLISHED,RELATED -g natctrl_tether_counters

/system/bin/iptables -A natctrl_FORWARD -i ap0 -o eth0 -m state --state INVALID -j DROP

/system/bin/iptables -A natctrl_FORWARD -i ap0 -o eth0 -g natctrl_tether_counters

/system/bin/iptables -A natctrl_tether_counters -i ap0 -o eth0 -j RETURN

/system/bin/iptables -A natctrl_tether_counters -i eth0 -o ap0 -j RETURN

/system/bin/iptables -D natctrl_FORWARD -j DROP

/system/bin/iptables -A natctrl_FORWARD -j DROP

echo 1 > /proc/sys/net/ipv4/ip_forward

其中,ap0是連接內網的網卡,eth0是連接外網的網卡。

  • 上一篇:想要用python3做個軟件對網頁自動化操作,需要搭建什麽環境,如何實現?
  • 下一篇:求壹個NBA2KOL的按鍵精靈腳本 或者輔助 要完美投籃的
  • copyright 2024編程學習大全網