Usually when attack is in progress, one hardly can access the server to work with it. In such case, contact your server provider to mitigate the attack. In case you can access it, there are some tips what you can do:

1) temporarilly stop httpd (webserver) and mysqld (database server) service (example: service httpd stop;service mysqld stop) to see if server load decrease (command: w). Then checking server logs in /var/log directory (cd /var/log;ls -lht)

logs can be checked using command "tail"

tail logfilename
tail -n30 logfilename (last 30 lines of the file)
tail -f logfilename (shows the live output)

2) discover which IPs / IP ranges hitting Your server and which port is affected

To find out bad attacking IPs, it may help to do the command:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
it will show IPs and number of their connections. >50 connections by single IP on a webserver starting to be alot..

details of an IP with many connections: whois IPADDRESSHERE

Second command is to show number of connections per linux port/service:

netstat -tuna | awk -F':+| +' 'NR>2{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
this way one can try to disable service which listen to the port with most connections and then study logs
example port 80 has 12000 connections, stop httpd service (service httpd stop or /etc/init.d/httpd stop)

3) Block bad IPs / IP ranges in firewall:

BAN in iptables
iptables -I INPUT -s -j DROP (-I = insert IP, ban IP in this case)
UNBAN from iptables
iptables -D INPUT -s -j DROP (-D = delete IP from iptables, allow in this case)

Other low importance (time waste) step:
You can also add bad IPs to your websites .htaccess file to prevent website based attacks (but this is usually not much efficient):

.htaccess :
order allow,deny
deny from
deny from 8.7.4
allow from all
you may also add file caching rules into .htaccess like:

#3 Remove ETags
Header unset ETag
FileETag None

# 480 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$" >
Header set Cache-Control "max-age=290304000, public"

# 2 DAYS
<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"

<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
(but these dont prevent DDoS, rather decrease server load sligtly in some cases)

4) Install 3 softwares to automate blocking of bad IPs

Low size attacks can be denied/IP blocked automatically by 3 software traffic/log monitors (CSF/LFD, DDoS Deflate and Fail2Ban), i have them all at once on some server:

- install DDoS Deflate, here is the install guide for DDoS Deflate:

- Next thing to install is Config Server Firewall, read Config Server Firewall installation guide here:

- Third mitigation anti DDoS software for Linux is Fail2Ban. Read quick installation guide:

If You have any good ideas to enhance this tutorial, please kindly share, thanks