How to add a blacklist to Apache2 and block IP Addresses on the whole server

Block out strange visitors IP addresses with a Apache2 Blacklist.

Sometimes one find’s some strange visitors coming to their websites. These strange visitors may or may not identify them selves with a 1995 type display resolution of 1024 by 768 while pretending being an iPhone. Very strange. Such visitors are not real users and them visiting my sites is not my intention. Therefore I have applied a little Blacklist which blocks IP addresses on the whole server.

How to implement a Apache2 Blacklist

Now let me explain the little steps to implement such a IP blacklist for Apache2.

First you need to create a configuration file in /etc/apache2/conf-available

nano /etc/apache2/conf-available/ip-blacklist.conf

and past in this content into it:

<Location />

order allow,deny

#Blacklisted IP's
#deny from xxx.xxx.xxx.xxx


# allow everyone else in
allow from all

</Location>

and to block an IP address, you just enter a new line below #Blacklisted IP’s with “deny from IP ADDRESS”. Save the file and enable the blacklist and reload Apache2 with:

a2enconf ip-blacklist
service apache2 reload

And your blacklist is in place and effective now.

How to create a Blacklist in Apache2 to block IP addresses
How to create a Blacklist in Apache2 to block IP addresses

Is there a blacklist file?

There are many IP Blacklists for blocking certain IPs, Networks and Subnetworks. I found a Blacklist on Github, blocking many many networks. But to avoid blocking out real visitors, I would recommend to block IP addresses one by one.

Leave a Reply

Your email address will not be published. Required fields are marked *

*