Jump to content

Allow IP blocks with htaccess, block rest


fr600

Recommended Posts

I'm looking forward to make my server private. I'd like to grant access to some specific IP blocks and deny access from the rest. I know it can be done using htaccess but I don't know how. These are some of the blocks that I'd like to allow access:

 

122.202.0.0 - 122.202.31.255

158.165.224.0 - 158.165.231.255

158.145.176.0 - 158.145.191.255

178.141.228.0 - 178.141.228.127

180.78.20.172 - 180.78.20.179

195.12.167.228 - 195.12.167.231

217.110.163.192 - 217.110.163.223

 

Moreover, I'd like to redirect the banned users to some other website like: www.google.com

 

Could you please help with this? Thanks.

Link to comment
Share on other sites

I took this from a website, in your .htaccess file you will write this:

 

## USER IP BANNING
<Limit GET POST>
order allow,deny
deny from 42.12.5.34
deny from 212.173.53.
deny from 69.242.
allow from all
</Limit>

 

Heres how it works

 

    * 42.12.5.34 (Blocks a specific IP address)

    * 212.173.53. (Blocks ALL IPs within the range 212.173.53.xxx)

    * 69.242. (Blocks ALL IPs within the range 69.242.xxx.xxx)

    * 81.158.3 (Blocks ALL IPs within the range 81.158.3xx.xxx.xxx)

 

Link to comment
Share on other sites

Does this mean that for "122.202.0.0 - 122.202.31.255" I'll have to write 32 different entries?

 

I can't do that, otherwise my htaccess will be like 1000 line long. The list IP I showed here is just an example which will help me to understand how it works and I can use the knowledge with the rest.

 

There must be a shorter way. I found like 100s of websites like that, but that doesn't help. Hoping for a better solution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.