Home · Gallery · Games · Links

October 9, 2006

IP Banning with htaccess

Category: Hack The Planet — Feydakin @ 9:30 pm

Blocking access to your website by banning ip addresses and ip ranges is becoming more and more of an issue as the spammers get more and more agressive, especially with blog spam.. Blocking a single ip address is pretty much a useless effort, but it is possible to block wide ranges of addresses with a simple command in your .htaccess file..

First, your .htaccess file for blocking IP addresses should be in the root of your web space.. If you don’t have one, or don’t know how to edit yours, check with your ISP.. Making a mistake in the .htaccess file can cause your website to be unreachable..

Once inside your htaccess file you need to add this simple code..


# Ban IP addresses
order allow,deny
deny from 192.0.0.0
allow from all

With this command we are telling the system to denay access to the ip address 192.0.0.0.. You can add as many lines as you want or new by simply adding more lines..


# Ban IP addresses
order allow,deny
deny from 192.0.0.0
deny from 292.0.0.0
allow from all

You can also block larger pools of ip addresses by dropping the last octet, or more, of numbers..


# Ban IP addresses
order allow,deny
deny from 192.0.0
allow from all

This would block all IPs from 192.0.0.0 to 192.0.0.255.. This can come in handy when trying to block huge regions that harbor spammers such as parts of Asia.. You can go one level deeper and block at 192.0 and block all addresses from 192.0.0.0 to 192.0.255.255.. That is a lot of adresses (over 65,000)..

Just remember not to block too large of a range.. You could wind up blocking potential customers.. And, just to make things even less fair, it’s not hard to proxy your ip address and get around this block anyway.. But it can be helpful in slowing down some of the less intelligent spammers out there..

~Fey

Spread It:
  • del.icio.us
  • De.lirio.us
  • NewsVine
  • Netvouz
  • Reddit
  • StumbleUpon
  • Technorati
  • Propeller
  • Digg
  • Facebook
  • LinkedIn
  • Mixx
  • Pownce
  • Sphinn
  • TwitThis

No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .