7

How can I use iptables in an Android application? I need this for a firewall-like functionality i.e. packet filtering, blocking sites etc.

I'm also not sure whether iptables are available in the Android kernel.

I previously heard that I'd have to create cross-compiled binaries of iptables – but how can I do that? And how can I use them in the application?

slhck
  • 36,575
  • 28
  • 148
  • 201
Preetam
  • 5,528
  • 10
  • 32
  • 39

1 Answers1

5

It's definitely possible. You might consider looking at the source code of Droidwall.

DroidWall - Android Firewall is a front-end application for the powerful iptables Linux firewall. It allows you to restrict which applications are permitted to access your data networks (2G/3G and/or Wi-Fi).

Check out the iptables API from Droidwall for specific examples.

Note that when using iptables you need root access to your phone.

slhck
  • 36,575
  • 28
  • 148
  • 201
  • i saw that,but how do i create that iptables binary....and use it inside the application... and what it will contain. – Preetam Jan 11 '11 at 14:51
  • now that android kernel does not have iptables inbuilt, so whether that binary only will supply the functionality? so that means rules have to be put inside once..and in the droidwall, the main api which handles the communication between the main application and the iptables contains some rules and some shell script that will may be executed in the kernel. – Preetam Jan 11 '11 at 14:54
  • so how can rules be edited dynamically... and actually i plan to keep rulesets in an seprate file...and only when the internet connection is activated, the file will be loaded in the memory and interface with the iptables... – Preetam Jan 11 '11 at 14:58
  • i dont know how far clear i am able to make myself...but this is what i need to do... – Preetam Jan 11 '11 at 14:59
  • I'm sorry, I don't really have the time to look into that. Maybe make your question clearer by putting your comments in it and somebody has a clue! – slhck Jan 11 '11 at 15:15
  • ok..i am still studying iptables thoroughly.. and some android internal as well... lets c if i can find some way out... – Preetam Jan 12 '11 at 04:40
  • anyways...thankyou very much for giving time to answer the Q. – Preetam Jan 12 '11 at 04:41