Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blocking IP range in htaccess file

I'm managing a site and the site is built in Wordpress. It gets ENORMOUS amount of traffic from bots and we want to block all of them except for important bots like Google Yahoo Bing Baidu. We use cloudflare and I want to block them from two layers, Cloudflare firewall and htaccess file. In htaccess file, I know how to block a single IP address and last trailing IPs of a IP range like 123.123.123.0/16

However, I need to block following IPs 69.30.192.0 - 69.30.255.255 93.55.115.64 - 93.55.115.71

How do you set rules of this in htaccess file? Cloudflare seems to follow same rule.

like image 522
Jason Marsh Avatar asked Feb 26 '16 04:02

Jason Marsh


People also ask

How do I block an IP address using htaccess?

In this tutorial, you've learned the easy way to block or allow visitors from specific countries. All you need to do is generate the country's IP address via Country IP Blocks, then insert an access control list (ACL) into your . htaccess file.

How can I allow or block a specific IP address for my website?

How to manage access with an IP Manager? Go to Hosting → Manage → IP Manager: There, you will be able to find 2 options: add IPs to allow and block access to your website: Just add an IP you wish to create rules for, leave a note (optional) and click on Add.


1 Answers

You've almost got it. The /16 notation is actually called CIDR Notation.

The number indicates how many bits to match from left to right. The Wiki page explains it in depth.

Or... you can just take my word for it and use a tool like this one I found: http://www.ipaddressguide.com/cidr#range

You can then use the deny from in your .htaccess just as you would for a single ip with the given values:

Order Allow,Deny
Deny from 69.30.192.0/18
Deny from 93.55.115.64/29
Allow from all
like image 52
Nick Kuznia Avatar answered Oct 06 '22 00:10

Nick Kuznia