There are two parts to what you need to do:
1 - create the IP tables filters and 2 - configure your system to restore them upon restart.
I would also REALLY suggest
this blog. It is a very well written introduction to IP tables and it is where I finally began to understand how to use it. Having said that, I am also of the opinion that it is best to learn how to write the IP tables commands, but there are also simple front end tools for it, so you may want to look at what your distribution offers.
As far as writing the rules, you will simply add a set of filters to your input chain. The IPtables rules will work like a waterfall and if a given connection matches a rule, the process will terminate. If it does not match, it will go on to the next rule and try that one. You will want to set up a default policy or an ending rule that drops all traffic. Above this rule, you will whitelist the connections that you want to add. At the top of your filter, you will will want white list established connections and things like your loopback interface.
Here is an example to help get you started. You would add this to IPtables: iptables -A INPUT -i lo -j ACCEPT (you will likely need to run as root or use SUDO on the command). This command adds (-A), to the INPUT chain, the lo interface (-i lo) the accept action (-j ACCEPT). You will want similar commands for your established connections and then the services you want to use. Here is a small set of what you will want:
Code:
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp -0 eth1 --dport 22 -j ACCEPT
-A INPUT -j DROP
The above example adds the loopback, established connections and TCP on port 22 for SSH and then finally drops everything else.
Now as far as saving and restoring, the best way to do this is to first create your filters as above. Then use the command iptables-save to save the IP tables commands to a file. You can then add a section to your network interface configuration to iptables-restore these commands upon startup.
This thread has a link to doing so, but here is the short version:
Code:
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.using
post-down iptables-save > /etc/iptables.using