【问题标题】:Blocking multiple ip ranges using mod access in htaccess在 htaccess 中使用 mod 访问阻止多个 ip 范围
【发布时间】:2013-08-24 22:55:30
【问题描述】:

我从 apache 网站阅读了该指南,但我有点困惑,我正在尝试使用以下语法禁止某些范围:

命令允许,拒绝 从 127.0.55.0/127.0.75.255 拒绝 从 127.0.235.0/127.0.255.255 拒绝 允许所有人

但我认为它不能正常工作,可能是语法错误或者我以错误的方式使用它,我应该在 htaccess 哪里写这个文本?在其他行之前还是之后?在同一个 htaccess 文件中也有一些 mod 重写脚本(用于防盗链)。

【问题讨论】:

    标签: apache .htaccess ip range mod-access


    【解决方案1】:

    我使用apache documentation 得出了这个答案。

    您可以使用 ip/网络掩码对给出地址范围:

    deny from 127.0.55.0/24
    

    但是,由于范围 55 - 75 不是 2 的幂,所以我不知道如何从中得出范围。我会添加几条规则。

    order allow,deny
    deny from 127.0.55.0/24  // Matches 55
    deny from 127.0.56.0/21  // Matches 56 to 64
    deny from 127.0.64.0/21  // Matches 64 to 71
    deny from 127.0.72.0/22  // Matches 72 to 75
    
    deny from 127.0.235.0/24 // Matches 235
    deny from 127.0.236.0/22 // Matches 236 to 239
    deny from 127.0.240.0/21 // Matches 240 to 255
    allow from all
    

    应该可以。

    注意:在粘贴到 htaccess 之前删除 // 之后的 cmets

    【讨论】:

    • 我对IP和htaccess有点新手,我认为IP中的数字是按升序排列的,例如:127.0.55.0、127.0.55.1、127.0.55.2等,或者它不像那个?
    • 当然可以。我在回答中写的是 IP/网络掩码对。网络掩码允许对 IP 地址进行分组(就像过滤器或正则表达式对文本所做的那样,网络掩码对 IP 地址进行分组)。所以 127.0.55.0/255.255.255.0 匹配 127.0.55.* ;而 127.0.56.0/255.255.248.0 匹配 127.0.64.0 到 127.0.71.255
    • 更多解释:here 是计算子网掩码的一些步骤。
    • 我测试了这个方法,但是 htaccess 一直忽略 IP,然后我使用了 CIDR 转换器,这种格式现在可以工作了:拒绝来自 127.0.55.0/24 拒绝来自 127.0.56.0/21 拒绝来自 127.0。 64.0/21 拒绝来自 127.0.72.0/22
    • 在 apache 2.4 deny from 上已被 Require not ip 更改来源:httpd.apache.org/docs/2.4/fr/howto/access.html
    【解决方案2】:
    order allow,deny
    deny from 2001:4200::/32
    deny from 2001:4210::/32
    deny from 2001:4218::/32
    deny from 2001:4220::/32
    deny from 2001:4228::/32
    deny from 2001:4238::/32
    deny from 2001:4248::/32
    deny from 2001:4250::/32
    allow from all
    

    按照这些思路,如何为一个很长的拒绝列表添加一个重定向到另一个网站,该列表在 htaccess 中阻止了很多国家

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-09
      • 2015-04-21
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-29
      • 1970-01-01
      相关资源
      最近更新 更多