Would you like to learn how to install Apache and deny access to an IP address list? In this tutorial, we are going to configure the Apache server to block the access from an IP address list.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache – Blocking an IP address list

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Create a file containing the list of IP addresses.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Configure the file permission.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will forbid access from IP addresses included on the file named BLACKLIST.

From a computer included on the list, open the browser and enter the IP address of your web server.

In our example, the following URL was entered in the Browser:

• http://192.168.2.110

The Apache server will deny access and display an error message.

Apache - Block IP address

Congratulations! You created an IP-based access-list on the Apache server.

Tutorial Apache – Blocking an IP address network

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the default website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Create a file containing the list of IP addresses.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Configure the file permission.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will forbid access from IP addresses included on the file named BLACKLIST.

In our example, we blocked the entire network 192.168.10.0/24.

In our example, we blocked the entire network 192.168.20.0/24.

From a computer included on the list, open the browser and enter the IP address of your web server.

In our example, the following URL was entered in the Browser:

• http://192.168.2.110

The Apache server will deny access and display an error message.

Apache - Block IP address

Congratulations! You created an IP-based access-list on the Apache server.