Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We're using HAproxy as a front end load balancer / proxy and are looking for solutions to block random IP addresses from jamming the cluster.

Is anyone familiar with a conf for HAProxy that can block requests if they exceed a certain threshold from a single IP within a defined period of time. Or can anyone suggest a software solution which could be placed in front of HAProxy to handle this kind of blocking.

share|improve this question

migrated from stackoverflow.com Dec 2 '09 at 20:17

This question came from our site for professional and enthusiast programmers.

3 Answers 3

fail2ban is able to add firewall (iptables) rules to block traffic in response to logfile entries so if you can make HAProxy write log entries for requests, fail2ban can rate limit for you.

share|improve this answer

Just use regular IPtables. Example below is for ssh, hopefully you get the idea.

from http://www.debian-administration.org/articles/187

iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP

There is also "hashlimit" module, but I haven't tried that

share|improve this answer

Depending on whether you wish for the denied ips to be retained over reboots or not. These routes are lost during a reboot (unless you add to rc.local etc). But in a pinch when I have had nasty people hammering at some of our systems I just add a null route to the haproxy server.

route add -host[net] Target[/prefix] gw 127.0.0.1

This is fast, does not require editing iptables and can be pulled simply by removing the route.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.