Ban IP Addresses With Your .htaccess File

August 13th, 2007 by admin

It is inevitable that sooner or later you will get a visitor to your site that will, in one way or another, become a nuisance. For example, perhaps some user comes in an keeps posting SPAM to your forum. Wouldn’t it be nice to be able to ban this users IP address or even their IP range? This can easily be done if you are on an Apache server by just using your .htaccess file.

Once you find the IP address of the user(s) you wish to ban (example: 123.255.123.1), just add them to the .htaccess file with an entry like so:

deny from 123.255.123.1

Perhaps this isn’t enough because the user has a dialup account with their ISP and just hangs up, calls back, and gets a new IP. Most of the time, the ISP will have the same first 2 sets of numbers, as our example shows: 123.255. You can eliminate that entire range:

deny from 123.255.

You should be VERY CAREFUL when you do this because you could have just denied access to everyone from a popular ISP such as AOL, MSN, etc.. Sometimes if you are under attack from such users you have no choice but to temporarily ban an entire ISP. There are a few good tools to find out the ISP of an IP address:

American Registry for Internet Numbers (ARIN): http://arin.net/

&

RIPE NCC: http://ripe.net/

Generally, these services will not tell you any information about the user themselves, but will list out ISP information and how to contact their abuse departments.

This entry was posted on Monday, August 13th, 2007 at 11:12 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply