Simple Linux Firewall with Lokkit
Most Linux distros have ipchains or iptables available however writing your own rules is kindof a pain.
There are multiples tools to help with this.
Here i'm gonna use "Lokkit
It's very small and simple.
If you are on a desktop it has a web interface (Gnome), and if you are on a server, you can configure it from the console with it's n-curse based interface.
sudo apt-get install lokkit
We use "-n" which mean "don't start the firewall", so we can review the firewall first and not lock ourselves out by accident like idiots.
You will want to keep the setting to high, and click "customize to enable the services you need, for example on a web server maybe SSH, WWW, 443(https), 25: mail smtp, 993(imap) etc ...
Then we can checkout the generated rules and make sure it seems ok
Just in case, you might want to add an entry to the crontab so that it shuts down the firewall in 5mn, just in case the firewall locks you out:
#sa it's 1:58 right now, so stop it at 2:05.
05 02 * * * /etc/init.d/lokkit stop
Ok now we can start the firewall, and test it (make sure whatever should be opened is).
If all goes well, don't forget to remove the crontab entry !
crontab -e remove the line: 05 02 * * * /etc/init.d/lokkit stop