Skip to content
Advertisement

Any way to ensure that no more than x HTTP requests are sent to a certain site in Linux?

I am using Docker, base image is alpine. I have an application that sends HTTP GETs to a certain site but I have a limitation, after 50 requests I have to pay some amount per request and I want to avoid that. I will also impose some sort of hard stop from the application code but I wanted to know if there is some way of also doing this from Linux, just in case. Is there any way to do this?

Advertisement

Answer

At the Linux Operating System level, the blocking of outbound requests can be done in these 3 ways:

  1. iptables outbound rule

iptables -A OUTPUT -o eth0 -p tcp –syn –dport 80 -m connlimit –connlimit-above 50 -j DROP

  1. Linux Traffic Controller (tc)

More information:

http://man7.org/linux/man-pages/man8/tc.8.html

https://netbeez.net/blog/how-to-use-the-linux-traffic-control/

  1. Application proxy (squid or cuttle)

More information:

https://www.linuxhelp.com/how-to-limit-bandwidth-squid

https://github.com/mrkschan/cuttle

3 People found this is helpful
Advertisement