I have a dedicated server with 32GB RAM. It works all fine till some punters came to ddos my server. I had really high uplink bandwidth usage (over 150Mbps). I looked at netstat with the following command:
netstat -an | grep tcp | awk '{print $5}' | cut -f 1 -d : | sort | uniq -c | sort -n
It shows thousands of connections for multiple IPs: I used following iptable rules to limit connections per IP:
iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 15 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
iptables -A INPUT -m state --state RELATED,ESTABLISHED -m limit --limit 150/second --limit-burst 160 -j ACCEPT
I saved these rules and these rules are top in the list in iptables. I restarted the system to close all the connects and restored the iptable rules. Put the server online. Server was almost dead and there were thousands of connections again. I have UFW installed and only couple of ports are open.
What can I do to stop it? How can kill established connections per ip? BTW. all the ips are masked and fake ones.
Edit:
netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n
1 CLOSING
1 established)
1 Foreign
2 SYN_SENT
7 FIN_WAIT2
16 LISTEN
21 CLOSE_WAIT
48 LAST_ACK
209 SYN_RECV
284 FIN_WAIT1
772 ESTABLISHED
35426 TIME_WAIT
output of iptraf -d eth0
IPTraf
l Statistics for eth0 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
x x
x Total Total Incoming Incoming Outgoing Outgoing x
x Packets Bytes Packets Bytes Packets Bytes x
x Total: 332826 128344K 192313 14538688 140513 113805K x
x IP: 332826 123518K 192313 11679988 140513 111838K x
x TCP: 332692 123507K 192311 11679924 140381 111827K x
x UDP: 0 0 0 0 0 0 x
x ICMP: 134 11448 2 64 132 11384 x
x Other IP: 0 0 0 0 0 0 x
x Non-IP: 0 0 0 0 0 0 x
x x
x x
x Total rates: 31150.2 kbits/sec Broadcast packets: 0 x
x 25144.8 packets/sec Broadcast bytes: 0 x
x x
x Incoming rates: 8907.0 kbits/sec x
x 14266.2 packets/sec x
x IP checksum errors: 0 x
x Outgoing rates: 22243.2 kbits/sec x
x 10878.6 packets/sec