I'm slowly working my way through learning basic security for my new Linode. I'm currently trying to decide on the best way to configure a simple firewall, however I'm somewhat confused over which method would be best for me and my situation.
At the moment, I'm building a LAMP server with email (Postfix/Dovecot) in order to host my own projects, starting with a blog but moving towards indie game development down the track, so I'm trying to be up to small business levels of functionality. Whatever I host there it's going to be just me who needs access, so I can limit things down pretty severely. Once I get this Linode running smoothy, I also don't want to have to spend too much of my time doing basic maintenance. But on the flipside I do want to at least have a basic understanding of what's going on so I can actively avoid serious issues.
Currently I
think I've locked down SSH access pretty tight. You can only log in as a single specified non-root user with a public access key (no password access) on a non-standard port. I think the only further thing I could do is lock down the IPs, but given my home ISP access doesn't have a static IP and there's a not insignificant chance I might need to change ISPs in the future, I think that might be overkill. I don't think it's likely someone will break in via SSH, but I don't know enough about problems with other ports or whether I need to worry about attacks being an issue simply because of their sheer numbers.
I'm thinking from what I've read that for firewalls, I probably just need a simple method of stopping brute force attacks after a certain number of failed attempts.
My current firewall is a very simple iptables bash script that I wrote from the info in this tutorial and linked to from /etc/rc.local:
http://www.howtoforge.com/linux_iptables_sarge
Here's the code, modified a bit in case anyone uses it with their SSH port and IP address (note though that I'm brand new at this, so use at your own risk

):
Code:
#!/bin/sh
iptables=/sbin/iptables
myip= # insert your server IP address in here!
mysshport=22 #or whatever you changed it to!
# clear the tables just in case anything was already set...
$iptables --flush
# make sure I can log in...
# SSH
$iptables -A INPUT -p tcp --dport $mysshport -j ACCEPT
# the basics
$iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$iptables -A FORWARD -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
$iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
# anything I want to reject (make sure it's not me!)
# bad guys, spammers, add them here...
# MySQL (remote access)
# do I need access to MySQL? Might need to fix this line if I do...
# $iptables -A -d $myip -p tcp --dport 3306 -j ACCEPT
# Email/Postfix
$iptables -A INPUT -d $myip -p tcp --dport 25 -j ACCEPT
# HTTP/Apache
$iptables -A INPUT -d $myip -p tcp --dport 80 -j ACCEPT
# SSL/Apache
$iptables -A INPUT -d $myip -p tcp --dport 443 -j ACCEPT
# IMAP
$iptables -A INPUT -d $myip -p tcp --dport 587 -j ACCEPT
# IMAPS
$iptables -A INPUT -d $myip -p tcp --dport 993 -j ACCEPT
# Localhost traffic
$iptables -A INPUT -d $myip -s 127.0.0.1 -j ACCEPT
# ICMP/Ping
$iptables -A INPUT -d $myip -p icmp -j ACCEPT
# Reject everything else
$iptables -A INPUT -j REJECT
$iptables -A OUTPUT -j REJECT
$iptables -A FORWARD -j REJECT
If I understand what I've done correctly, I've allowed access to the ports I need while blocking everything else, which is a pretty straightforward place to start.
Now I want to put in a temporary block for anyone trying to do repeat requests, but not in such a way that it's likely that it will block
me out.
I've had a look at fail2ban, but I was finding it hard to understand how to configure it, or more accurately how to configure it for what I wanted to do. I found some tutorials on their website nothing that went through and told me explicitly what each option did, which made me a bit nervous given I wanted to set it to a non-standard SSH port.
I've also heard about DenyHosts, which I'm reading about now but am unsure if it's really what I need. It's not iptables based either, which may or may not be a good thing - I'm not sure.
The other option which I've seen mentioned is I could just write a few custom iptables lines myself, which I guess would go under the "bad guys" comment I've made in my simple iptables script. I'm not entirely sure what those lines should be, though

. I can get what most of that code I've used does, but there's a few options on those RELATED,ESTABLISHED lines I'm a bit shaky on. Still, if it's only a few lines or someone knows of a good tutorial it could be a good way to learn more about how the network works.
I don't think I need anything too fancy, but then again I'm new at this and I'm not really sure what level of action I should be taking here. I'd like to hear what recommenations more experienced server administrators would make to a beginner in my situation.
Thanks!