You are not alone.
This tutorial will do more than throw code at you. I will explain the entire process. You will leave with an understanding of how to do it, but why its done that way.
The best thing to do us start with a clean slate. By the time you get here, you probably have either no firewall, or the well meaning one from your OS, or a sorta implementation that you think is working...
This is a universal "back it up and start it over" script for IP tables.
Ok, so now that that's done we can get to business. Lets start with a simple web server:
So, why do I DROP on INPUT and REJECT on FORWARD? DROP and REJECT do essentially the same thing: deny access to traffic. The difference is that DROP will simply not respond. REJECT will send the proper "I'm not listening to you" message. I say "proper" with clenched teeth. While it is useful for debugging, politeness can be used against you. Port scanners can see a "REJECTED" port, and my evil counterpart will know you are are trying to hide something.
With DROP (s)he not only gets no feedback at all, it takes a port scanner a longer time to handle a drop because they wait for the return that never comes. A REJECT gives them instant gratification.
Security is like poker, never show your cards. If a blackhat sees that you have a copy of MySQL or Samba running (although blocked) on the box, he or she may think there is something to plunder. You don't leave a laptop on front seat of your car, you don't leave ports visible that you don't intend to be used.
So, after all this spiel about DROP on INPUT, why do I REJECT on FORWARD? FORWARD is used when your box tries to redirect traffic on behalf of another computer. While a normal web server doesn't have to deal with this, if you ever employ a VPN tunnel or a PPP connection, your kernel may or may not have to "FORWARD" traffic to make the magic happen properly. When diagnosing problems the feedback from a REJECT versus the silence of DROP is the difference between a quick tweak to an afternoon of frustration until you remember how you locked the machine down. Besides, blackhatters who try to forward through your box do get the idea after the first couple of attempts.
Now you aren't completely out of the woods yet. There are a lot of attacks against SSH on the default port, so be sure to read up on my later chapter "SSH on a non-standard port".
You are also going to need some way of restoring this IPTABLE firewall once your operating system reboots. See my later chapter "Firewalls on Startup".
Index: Evil Twin Skippy's Guide to Linux | Back: Who is Evil Twin Skippy?