How to Block an IP address range using the .htaccess file

若如初见. 提交于 2019-11-26 15:55:48

问题


I have detected that a range of IP addresses may be used in a malicious way and I don't know how to block it.

I would like to block the range 66.249.74.* from accessing my website by using the .htaccess file.


回答1:


You could use:

Order Allow,Deny
Deny from 66.249.74.0/24
Allow from all

Or you could use this:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} ^66\.249\.74\.
RewriteRule ^ - [F]



回答2:


Use just the first 3 octets

Order Allow,Deny
Deny from 66.249.74.
Allow from all



回答3:


I’ve just used

Order Allow,Deny
Deny from 188.143.*.*
Allow from all

as spam attack comes from xxx.xxx.0-80.0-80.




回答4:


You can go to: and enter ips and it will generate the file for you. http://www.htaccesstools.com/block-ips/

Also for example you want to block the ip address range you want would be:

Order Allow,Deny
Deny from 66.249.74.0/24
Allow from all

Or You Can Do:

You can indicate which addresses you wish to block using RewriteCond %{HTTP_REFERER}.

This is a Working Example:

# BLOCK VISITORS REFERRED FROM GOOGLE.COM

RewriteCond %{HTTP_REFERER} ^https?://([a-z0-9-]+\.)?google\.com [NC]
RewriteRule .* - [F]

The example above uses a regular expression, so it will block:

  • https:// or http://
  • followed by any subdomain (or none)
  • followed by google.com
  • followed by anything (or nothing)

The [F] flag means Forbidden. The server will return a 403 Forbidden Error.




回答5:


you can do it easily by adding IP Ranges to your .htaccess file by downloading the full ranges from https://www.ip2location.com/blockvisitorsbycountry.aspx and uploading the .hataccess back to the directory you want blocked.

I recently blocked Russia by this method cause of getting loads of spam registrations on my forum and the forum never needs any contribution from this country.




回答6:


eg:

<Files *>
order deny,allow
deny from 2.72.0.0/13 2.92.0.0/14 2.132.0.0/14 
</Files>

Great howto with ip ranges here:

http://www.wizcrafts.net/russian-blocklist.html

Also these are up to date lists of offending ip ranges.



来源:https://stackoverflow.com/questions/18483068/how-to-block-an-ip-address-range-using-the-htaccess-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!