Hi,
I readed an advanced netfilter tutorial and, it is written that:
The iptables package comes with two more tools that are very useful, specially if you are dealing with larger rule-sets. These two tools are called iptables-save and iptables-restore and are used to save and restore rule-sets to a specific file-format that looks quite a bit different from the standard shell code that you will see in the rest of this tutorial.
Tip iptables-restore can be used together with scripting languages. The big problem is that you will need to output the results into the stdin of iptables-restore. If you are creating a very big ruleset (several thousand rules) this might be a very good idea, since it will be much faster to insert all the new rules. For example, you would then run make_rules.sh | iptables-restore.
Speed considerations
One of the largest reasons for using the iptables-save and iptables-restore commands is that they will speed up the loading and saving of larger rule-sets considerably. The main problem with running a shell script that contains iptables rules is that each invocation of iptables within the script will first extract the whole rule-set from the Netfilter kernel space, and after this, it will insert or append rules, or do whatever change to the rule-set that is needed by this specific command. Finally, it will insert the new rule-set from its own memory into kernel space. Using a shell script, this is done for each and every rule that we want to insert, and for each time we do this, it takes more time to extract and insert the rule-set.
This is definitely our case so I saved my firewall with iptables-save >/firewall.ipt and copied the startup script to /firewall.sh (only the used rules, i expanded if, for, case, etc.) and this is the result:
[/]# time ./firewall.sh
real 0m 9.89s
user 0m 3.71s
sys 0m 6.18s
[/]# time iptables-restore <firewall.ipt
real 0m 0.35s
user 0m 0.25s
sys 0m 0.10s
[/]#Now what do you think about this? A 10 sec speedup in boot will be appreciated in a router OS ![]()
