Buy @ Amazon

Blacklisting IP Addresses in Apache 2 Web Server

Operating System : Ubuntu

Web Server : Apache 2.4.48

Objective : Blacklist IP Addresses to block it accessing the web application

Steps To Finish Line: 

Step 1: Enable rewrite apache module by executing `a2enmod rewrite` in your bash terminal. Read a2enmod command as "Apache2 Enable Module". Its complementary command to disable an apache module is a2dismod. Putting it here, just in case you want to rollback your changes for whatever reason it be.

Step 2: Edit the Apache configuration file for the default website by executing `vi /etc/apache2/sites-enabled/000-default.conf` in your bash terminal to add the lines below:

so that the configuration file looks like below:

Step 3: Now create a file to hold black listed IP Addresses by executing command `vi /etc/apache2/blacklist` in your bash terminal and add your IP Addresses to be black listed like below in the file opened for editing in the previous step:

Step 4: You may have to change the blacklist file's ownership by executing the command in your bash terminal:

Step 5: Last step to reach the finishing line. Restart the apache2 web server with `sudo service apache2 restart` command in your bash terminal and check for its status by executing, `sudo service apache2 status` to see if it is running again.