Reputation: 199
I've the following code to block single ip address in htaccess and it works fine
SetEnvIF X-Forwarded-For 182.65.209.192 DenyIP
Order allow,deny
Deny from env=DenyIP
Allow from all
Now I want to block country ip addresses from visiting my site.
I tried this but not works
SetEnvIF X-Forwarded-For 37.230.192.0/19 DenyIP
and
SetEnvIF X-Forwarded-For 37.230.192.[0-19] DenyIP
instead of
SetEnvIF X-Forwarded-For 182.65.209.192 DenyIP
How to block the ip range or subnet ip (for ex: 37.230.192.0/19)?
Upvotes: 0
Views: 4617
Reputation: 143886
You can't match against CIDR address ranges, you need to use a regular expression. You want something like this:
SetEnvIF X-Forwarded-For 37\.230\.(19[2-9]|2[01][0-9]|22[0-3])\.[0-9]+ DenyIP
SetEnvIf Remote_Addr 37\.230\.(19[2-9]|2[01][0-9]|22[0-3])\.[0-9]+ DenyIP
SetEnvIF X-Forwarded-For 37\.230\.2[23][0-9]\.[0-9]+ DenyIP
SetEnvIf Remote_Addr 37\.230\.2[23][0-9]\.[0-9]+ DenyIP
Upvotes: 2
Reputation: 18671
SetEnvIF use regex:
http://httpd.apache.org/docs/current/en/mod/mod_setenvif.html#setenvif
You can use:
SetEnvIF X-Forwarded-For ^37\.230\.192\.[01][0-9]?$ DenyIP
Upvotes: 3