8

I'm reading through the source code that writes directly to system iptables in /system/xbin/iptables in Android. I would like to do the same in Ubuntu without using the iptables command.

Where is iptables located on Ubuntu 16.04? I followed some questions and answers which don't apply on this version of Ubuntu.

find / -name iptables return /sbin/iptables which contains binary and maybe man!

Where is the file that the iptables command writes its configuration?

  • According to what I see on my device, /system/xbin/iptables is a binary. I think the kernel stores the iptables in RAM as opposed to a place on the drive? – Kaz Wolfe Oct 27 '16 at 8:46
  • it stored on disk in android!, that mean rules need to be written after each reboot by my application? – Error Oct 27 '16 at 8:55
  • Ah, I get what you mean now. Okay. – Kaz Wolfe Oct 27 '16 at 8:56
10

iptables stores its information in RAM, meaning it's non-persistent. If you want to save/restore it at will, you'll need to use a couple commands.

First off, you would use iptables as normal to set up your rules the way you want them. Then, you can freeze these rules using something like:

sudo iptables-save | sudo tee /etc/iptables.conf

Then, to load your rules, it's a simple matter of running:

sudo iptables-restore < /etc/iptables.conf

You can add this to your /etc/rc.local or similar to have it run automatically at boot, or you can have your program call this executable (or just pass the same iptables rules over and over again).

| improve this answer | |
3

Instead of iptables, you should actually take consideration in using ufw, the default firewall configuration tool provided by ubuntu internally.

All of the settings on firewall, which was configured through iptables, could be stored through ufw, such as the configuration file located at /etc/default/ufw.

NAT is also possible to be configured and stored: https://gist.github.com/kimus/9315140

| improve this answer | |
0

Nothing is stored on disk for iptables unless you save the rules like so:

service iptables save

After you reboot, the rules that you save will be back in place. You can see that by doing an iptables -L to list the rules.

The rules are actually stored on disk (if saved) in /etc/sysconfig/iptables.

| improve this answer | |

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.