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

前端 未结 6 693
感情败类
感情败类 2020-12-02 20:12

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 acces

相关标签:
6条回答
  • 2020-12-02 20:46

    Use just the first 3 octets

    Order Allow,Deny
    Deny from 66.249.74.
    Allow from all
    
    0 讨论(0)
  • 2020-12-02 20:52

    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.

    0 讨论(0)
  • 2020-12-02 20:57

    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.

    0 讨论(0)
  • 2020-12-02 21:04

    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.

    0 讨论(0)
  • 2020-12-02 21:04

    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.

    0 讨论(0)
  • 2020-12-02 21:05

    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]
    
    0 讨论(0)
提交回复
热议问题