5

I'm reading source code that write directly to system iptables in /system/xbin/iptables in Android. I want to do the same in ubuntu without using iptables command.

where is iptables located on ubuntu 16.04, I followed some questions answers which doesn't apply on what version of ubuntu.

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

where is the file iptables command writes to.

  • 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
8

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).

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

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.