问题原文
原帖链接 · LPChip · CC BY-SA 4.0
I'm looking for a good way to block an entire IP range using .htaccess.
The problem I'm having is that the block I need to ban is 100 IP ranges big. From a programmer's perspective it should be easily doable, but I'm failing to get it done without adding 100 lines in my .htaccess file, and other techniques I tried did not work.
The IP Address range I need to block is for HUAWEI Clouds:
159.138.100.*to159.138.199.*
A keen eye spots that basically 159.138.1 is enough to block.
I tried the following without success:
Order Allow,Deny
Deny from 159.138.1
Allow from all
I also tried:
Order Allow,Deny
Deny from 159.138.1*
Allow from all
How can I block this IP range effectively using .htaccess?
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 4.0
IP ranges are specified in .htaccess using CIDR notation. The simplest rule that you could use would be
Deny from 159.138.0.0/16
Which would block slightly too much:
CIDR Range 159.138.0.0/16
Netmask 255.255.0.0
Wildcard Bits 0.0.255.255
First IP 159.138.0.0
Last IP 159.138.255.255
Total Host 65536
To block the exact range of 159.138.100.0 to 159.138.199.255 you would need several rules:
Deny from 159.138.100.0/22
Deny from 159.138.104.0/21
Deny from 159.138.112.0/20
Deny from 159.138.128.0/18
Deny from 159.138.192.0/21
Source: IP Range to CIDR calculator
I'm not sure where you got the IP range you are working with. This site lists 74 CIDR ranges for Huawai cloud service
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
