By pteli
Within few hours of launching my website (http://www.winstondigital.com) on a droplet, my Nginx access log is filled with access requests like this:
**61.160.213.56 - - [22/Feb/2016:11:22:13 -0500] “GET http://zc.qq.com/cgi-bin/chs/numreg/init? HTTP/1.0” 404 1564 “-” “-” **
First question is: how the domain “zc.qq.com” is mapping to my public IP address? When I ping “zc.qq.com”, it gives an IP address that is registered in China. It appears that many others on the internet are getting spammed by these kind of attack.
Second question is: How can I stop these requests at the firewall, before it hits my application server (Rails). It seems harmless as all these requests are returned with a “404 Not found” error code. Still it is filling up my log files and creating unnecessary traffic.
Anyone else is seeing this problem?
Thanks for your help in advance.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This is where iptables and a little cron job can be useful.
If you’re regularly being hit by the same IP addresses, to block them out make a rule using iptables. With spam, it’s best to simply drop the traffic so try :
iptables -I INPUT -s xx.xx.xx.xx -j DROP
This will block IP address xx.xx.xx.xx accessing your droplet. You can also use CIDR format to block a range of IP Addresses if necessary.
This is not, however, persistent across a reboot so I’d recommend making a little script and run it at boot time as a cron job.
Assuming you’re logged in as root (if not then su as required)
nano ~/load_iptables.sh
/sbin/iptables -I INPUT -s xx.xx.xx.xx -j DROP
/sbin/iptables -I INPUT -s yy.yy.yy.yy -j DROP
chmod 700 ~/load_iptables.sh
/root/load_iptables.sh
crontab -e
Then add the following to the crontab that opens :
@reboot /root/load_iptables.sh
This will then load and run your script as root each time you restart your server. To add new addresses to block, just add a new line to your load_iptables.sh script.
This is a basic way of dealing with spam. If you are comfortable with linux it’s definitely worth looking at something like fail2ban which is a much nicer automated way of snipping spam attacks in the bud :)
I hope that helps!
Regards, Mike
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.