Target:
Perform IP forwarding for devices within the same local network. (The real target is transparent proxy but the IP forwarding is a prerequisite)
Network setup:
All devices are in the same local network 192.168.0.0/16.
- main router
192.168.1.1 - Android phone
192.168.2.1(network interfacewlan0) - computer
192.168.2.10gateway set as192.168.2.1 - others like Raspberry Pi at
192.168.1.11
Android setup:
- Data disabled, only WiFi connects.
- rooted Android 10 (Pixel 2 XL)
- enabled ip forwarding by
sysctl -w net.ipv4.ip_forward=1 - netfilter: on all tables of nat, mangle, filter and raw, run
iptables -F -t <table_name>andiptables -X -t <table_name> - rp_filter: Disable by
sysctl -w net.ipv4.conf.all.rp_filter=0andsysctl -w net.ipv4.conf.wlan0.rp_filter=0
Result:
- the computer cannot access to the Internet,
ping,dig, browser, nothing works. - the computer connects to local devices without any problem (like ping router
192.168.1.1, SSH to the Raspberry Pi, or use FireFox through the SOCK5 proxy hosted on the Pi). - Android phone connects to the Internet perfectly.
Debug:
- using
iptables -t <table_name> -L -vto show packet count, all chains have some packets, *except theFORWARDchain of bothraw,mangletables showsChain FORWARD (policy ACCEPT 0 packets, 0 bytes). After some googling, rp_filter is the suspect but I'm sure it's turned off.
iptables) operates at higher OSI layer. What about IP routing (ip ruleandip route)? Are they set up correctly? Android doesn't usemaintable by default, unlike normal Linux distros. Related: How to send all internet traffic to a SOCKS5 proxy server in local network? and How to port-forward internet using Android Hotspot to PC? – Irfan Latif Nov 02 '20 at 19:43