2

How i can set iptables rule like this on my rooted Android phone:

iptables -t nat -A PREROUTING -i wlan0 -s 192.168.1.100 -p tcp --dport 80 -j DNAT -–to-destination 192.168.1.101:8080

... since Android iptables implementation doesn't support protocol by name and DNAT?

3

According to this question on Stack Overflow

  1. iptables is available in Android source distribution.
  2. Users of retail Android devices cannot access iptables binary. Even Android OS itself cannot access that binary. This is hard-coded in Android. Many devices also don't have iptables at all.
  3. The only way to access iptables binary is to build your own Android images. Check out http://randomizedsort.blogspot.com/2010/08/building-android-and-linux-kernel-for.html. Once you get comfortable with that process, check out http://randomizedsort.blogspot.com/2011/03/porting-iptables-1410-to-android.html.

iptables is a default module in , you can use netfilter to write c code to handle that.

For example, you can create an android project, and write a JNI file, use ndk-build to compile that, and then push the executable to the android file system to execute. And in the mobile end, you can adb shell to it, directly use iptables command as a root user, just like in Linux.

To check if your device supports iptables:

Issue the following command in ADB shell or in Terminal Emulator:

iptables -L -t nat

Alternatively you could try the beta of IP Tables app on Google Play to see if it does what you want.

There is also Droid Wall that you could try. It supports scripts that may help, e.g.

$IPTABLES -A "droidwall" --destination "192.168.0.1" -j RETURN
0

You can try AFWall+ for example. Available in Play Store and in F-Droid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.