Blocking Attacking IPs Behind a Webserver

Abstract: Block malicious IP ranges in Apache by configuring Require directives in virtual host files or .htaccess to reject unauthorized HTTP requests.

Created: 2026-09-07 by
To block attacking IPs behind an Apache web server, you can configure the Require directive in your virtual host file or use .htaccess to deny access from specific IP ranges like 201.17.83.xxx and 10.0.1.xxx. This method provides immediate protection against known malicious sources by rejecting their HTTP requests at the server level before they reach your application logic.

Identifying Malicious Traffic Sources

Before implementing blocks, it is crucial to verify that the identified IP addresses are indeed the source of the attack. Apache access logs provide a detailed record of incoming requests, including the client IP, timestamp, requested URL, and HTTP status code. By analyzing these logs, you can pinpoint patterns such as high-frequency requests, attempts to access sensitive files, or unusual user-agent strings associated with the suspicious IPs. In this scenario, the logs indicate activity from 201.17.83.xxx and 10.0.1.xxx. The 201.17.83.xxx range appears to be a public IP block, potentially originating from external attackers. Conversely, 10.0.1.xxx falls within the private IPv4 address space defined by RFC 1918. If your web server is exposed to the internet, seeing internal private IPs in public-facing logs might indicate NAT (Network Address Translation) issues, proxy configurations, or spoofed headers. It is essential to distinguish between direct attacks and misconfigured proxies to ensure you are not blocking legitimate traffic from your own infrastructure.

Blocking IPs via Virtual Host Configuration

The most robust way to block IPs in Apache 2.4 is through the main configuration or virtual host files. This approach ensures that the rules are applied consistently across all directories served by that specific virtual host. You should edit the relevant <VirtualHost> block in your Apache configuration directory, typically located at /etc/apache2/sites-available/ on Debian-based systems or /etc/httpd/conf.d/ on Red Hat-based systems. Inside the virtual host definition, add a <Directory> or <Location> block to specify the access control rules. Use the Require directive to explicitly deny the identified IP ranges. For example, to block the 201.17.83.0/24 subnet and the 10.0.1.0/24 subnet, you would use the following syntax:
<RequireAll>
    Require all granted
    Require not ip 201.17.83.0/24
    Require not ip 10.0.1.0/24
</RequireAll>
This configuration tells Apache to grant access to everyone (Require all granted) except for those matching the specified IP ranges. After saving the changes, you must reload the Apache service for the new rules to take effect. On systemd-based systems, run sudo systemctl reload apache2 or sudo systemctl reload httpd. Always test the configuration with apachectl configtest before reloading to prevent syntax errors from taking down your site.

Using .htaccess for Directory-Level Blocking

If you do not have access to the main Apache configuration files, or if you need to apply blocking rules to a specific directory rather than the entire virtual host, you can use the .htaccess file. This method is particularly useful for shared hosting environments where users cannot modify the global server configuration. Place the .htaccess file in the root directory of your website or the specific subdirectory you wish to protect. The syntax for denying IPs in .htaccess uses the Deny and Allow directives, which operate on a different logic than the Require directive used in virtual hosts. To block specific IPs, you first allow all users and then deny the malicious ones:
Order Allow,Deny
Allow from all
Deny from 201.17.83.0/24
Deny from 10.0.1.0/24
Note that the Order directive is deprecated in Apache 2.4. In modern Apache versions, you should use Require inside .htaccess as well, similar to the virtual host method:
<RequireAll>
    Require all granted
    Require not ip 201.17.83.0/24
    Require not ip 10.0.1.0/24
</RequireAll>
Ensure that the AllowOverride directive in your main Apache configuration allows .htaccess files to override access controls. If AllowOverride is set to None, your .htaccess rules will be ignored. For more granular control, you can also whitelist trusted IPs while blocking others, as discussed in our guide on User Access Whitelisted Using .htaccess File in Apache 2.4 Still Cannot See Internet Site?.

Handling Private IP Ranges and Proxies

The presence of 10.0.1.xxx in your public logs warrants special attention. Since this is a private IP range, it should never appear on the public internet unless it is being translated or proxied. If your server is behind a reverse proxy like Nginx or Cloudflare, the real client IP might be obscured, and the proxy's internal IP could be logged instead. In such cases, blocking 10.0.1.xxx might block your own infrastructure or legitimate users depending on your network topology. Verify your proxy configuration to ensure that the X-Forwarded-For header is correctly populated. If you are using a reverse proxy, consider configuring Apache to trust the proxy's IP and log the actual client IP from the header. This prevents confusion and ensures that your blocking rules target the true source of the attack. Additionally, check if the 10.0.1.xxx range corresponds to your internal monitoring tools or CI/CD pipelines that might be triggering the service page unintentionally.

Verifying the Block and Monitoring

After applying the blocking rules, it is important to verify that they are working as intended. You can use command-line tools like curl to simulate requests from the blocked IPs if you have access to machines within those networks. Alternatively, monitor your Apache error logs for 403 Forbidden responses from the targeted IPs. A successful block should result in these clients receiving a 403 status code when attempting to access your site. Continue to monitor your access logs for any new attacking IPs or changes in behavior. Attackers often rotate their IP addresses, so maintaining a dynamic list of blocked IPs might be necessary. Consider integrating automated tools like Fail2ban to dynamically update your firewall rules based on log analysis. For more information on automating crawler and bot blocking, refer to our article on Fail2ban: Updating apache-badbots.conf for Debian 12 to Block Traffic from Crawlers.

Frequently Asked Questions

How do I unblock an IP address after blocking it?

To unblock an IP, simply remove the corresponding Require not ip or Deny from line from your Apache configuration or .htaccess file. After editing, reload the Apache service to apply the changes immediately.

Can I block IPs based on country instead of specific addresses?

Yes, you can use the ModGeoIP module to block traffic based on geographic location. However, this requires downloading and maintaining a GeoIP database, which may impact performance and accuracy compared to specific IP blocking.

Why am I still seeing traffic from blocked IPs?

If blocked IPs continue to appear, check if they are using a different IP address or if they are accessing your site through a proxy. Also, verify that your Apache configuration was reloaded correctly and that there are no conflicting rules overriding your block.

Is it safe to block private IP ranges like 10.x.x.x?

Blocking private IP ranges is generally safe only if you understand your network architecture. If your server is behind a NAT or proxy, these IPs might represent legitimate internal traffic. Always verify the source of these requests before applying broad blocks.

What is the difference between .htaccess and virtual host blocking?

Virtual host blocking applies to the entire site and is more efficient, while .htaccess allows for per-directory rules. Virtual host configurations are processed faster because they are read once at startup, whereas .htaccess is read for every request.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More