I will show you howto install PSAD to block DDOS attacks (distributed denial of service) and port scan on a webserver. Here I will use Ubuntu 8.04 LTS server but it should be very similar on other distro.
PSAD scan iptables log file to generate the attack block. The problem is that when you log ALL packets as shown in other PSAD tutorials, it will slow down considerably your server if it's busy and generate huge huge log files (growing at a rate of 1meg per second or more). With simple iptables rules, we will only log traffic that look suspicious (5 new connections in 5 seconds for example).