How to prevent or stop DOS or DDOS or SYN attack on linux server
If there are lots of hits coming from particular IP address then there is a chances of DDOS attack. Below are some tweak settings in the csf firewall for DDOS or SYN_ATTACK.
First check hits are coming from which port. Mostly DDOS attack done on port 80 i.e in Apache port. Please note that you are using correct timing and values otherwise lots of IP get blocked on the server firewall.
Login to the server via ssh
Open the csf.conf file with vi /etc/csf/csf.conf
Search for “PORTFLOOD”
Add PORTFLOOD = “80;tcp;20;300”
Save the file.
Restart csf service (service csf restart)
This rule will block IPs that connects to port 80 via TCP more than 20 times within 300 seconds. Once the attack is normal then remove this rule from the csf firewall.