Take the 2-minute tour ×
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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